Study guide
6.11 NetworkPolicy Isolation & CoreDNS Resolution Diagnostics
Certified Kubernetes Administrator CKA
Track your progress as you read
Finished sections get a check mark.
1 Chapter 1: CKA Exam Environment & Cluster Architecture
1.1 CKA Exam Mechanics, Scoring & Remote Terminal Environment 1.2 Kubernetes Control Plane & Worker Node Components 1.3 etcd Architecture, Clustering & Raft Consensus 1.4 Initializing Clusters with Kubeadm 1.5 Highly Available (HA) Control Plane Topologies 1.6 Cluster Lifecycle & Step-by-Step Upgrades 1.7 etcd Snapshot Backup and Restore Procedures
2 Chapter 2: Cluster Extensions, Packaging & RBAC
2.1 Kubernetes TLS Certificates & PKI Infrastructure 2.2 Managing Kubeconfig Files, Users, & Contexts 2.3 Installing Cluster Components with Helm & Kustomize 2.4 Role-Based Access Control (RBAC): Roles & RoleBindings 2.5 ClusterRoles & ClusterRoleBindings 2.6 Custom Resource Definitions (CRDs) & Operators 2.7 Pod Security Standards (PSS) & Admission Controllers
3 Chapter 3: Workloads, Lifecycle & Pod Scheduling
3.1 Pod Lifecycle, Multi-Container Patterns & Init Containers 3.2 Deployments: Rolling Updates, Rollouts & Rollbacks 3.3 DaemonSets & StatefulSets Architecture 3.4 Batch Workloads: Jobs & CronJobs 3.5 Managing ConfigMaps & Sensitive Data with Secrets 3.6 Resource Requests, Limits & Namespace ResourceQuotas 3.7 NodeSelectors, Node Affinity & Anti-Affinity 3.8 Node Taints & Pod Tolerations 3.9 Autoscaling: Horizontal Pod Autoscaler (HPA) & Custom Metrics
4 Chapter 4: Services, Networking & Ingress Architecture
4.1 Kubernetes IP-per-Pod Model & CNI Plugins (Flannel, Calico, Cilium) 4.2 Services Deep Dive: ClusterIP, NodePort, LoadBalancer & EndpointSlices 4.3 Kube-Proxy Service Dataplane: iptables, nftables, IPVS & eBPF 4.4 CoreDNS Configuration, Resolution & Custom Forwarding 4.5 NetworkPolicies: Ingress, Egress & Default-Deny Isolation 4.6 Ingress Architecture, Controllers & Path-Based Routing 4.7 Gateway API: GatewayClass, Gateway, HTTPRoute & Traffic Splitting 4.8 External Traffic Ingress: NodePort, Cloud LoadBalancers & MetalLB
5 Chapter 5: Storage Architecture & Persistent Volumes
5.1 Ephemeral Volumes, EmptyDir, HostPath & Config Volumes 5.2 PersistentVolumes (PV) & PersistentVolumeClaims (PVC) Lifecycle 5.3 StorageClasses, Dynamic Provisioning & VolumeBindingModes 5.4 Storage Access Modes, Reclaim Policies & Volume Expansion 5.5 Container Storage Interface (CSI) Architecture & Drivers 5.6 StatefulSet VolumeClaimTemplates & Persistent Storage Workflows
6 Chapter 6: Advanced Troubleshooting, Monitoring & Maintenance
6.1 Systematic Kubernetes Troubleshooting Methodology 6.2 Node Failure, Kubelet Diagnostics & Systemd Services 6.3 Control Plane Failures, Static Pods & Component Logs 6.4 etcd Troubleshooting, Quorum Loss & Database Defragmentation 6.5 Pod Startup Failures, CrashLoopBackOff & OOMKilled Diagnostics 6.6 Workload Scheduling Failures & Resource Constraint Resolution 6.7 Container & Node Logging Architecture, Journalctl & Fluentd 6.8 Metrics Server, Resource Utilization & Kubectl Top 6.9 Service, Endpoint & Ingress Connectivity Troubleshooting 6.10 Storage Failures: PVC Pending, Mount Failures & Multi-Attach Errors 6.11 NetworkPolicy Isolation & CoreDNS Resolution Diagnostics
6.11 NetworkPolicy Isolation & CoreDNS Resolution Diagnostics
Key Takeaways Explain This Topic AI
Pods are non-isolated by default. Once selected for ingress or egress isolation, traffic in that direction is allowed by the union of applicable NetworkPolicy rules and otherwise denied.
NetworkPolicy enforcement requires a CNI plugin with policy engine support (such as Calico, Cilium, or Antrea); standard Flannel does NOT enforce NetworkPolicies.
A critical NetworkPolicy pitfall is blocking DNS: an isolated Pod needs UDP and TCP port 53 egress to the cluster DNS endpoints, typically CoreDNS Pods selected in kube-system.
In NetworkPolicy YAML, array items in the 'from' or 'to' blocks evaluate with OR logic, whereas multiple selectors inside a single object evaluate with AND logic.
CoreDNS issues (crash loops, lookup timeouts) typically stem from upstream DNS forward loops detected by the CoreDNS 'loop' plugin, misconfigured Corefile ConfigMaps, or network policy blocking.
Last updated: August 2026
NetworkPolicy Isolation & CoreDNS Resolution Diagnostics
Network security in Kubernetes relies on NetworkPolicies —declarative layer 3 and layer 4 packet filtering rules evaluated and enforced by the cluster's Container Network Interface (CNI) plugin. When network policies are misconfigured, applications experience silent connection timeouts, broken database links, and failed health checks.
Similarly, CoreDNS provides the internal service discovery backbone for the entire cluster. If DNS resolution breaks or degrades, microservices cannot locate peer services by name, leading to cascading application outages. Mastering NetworkPolicy isolation diagnostics and CoreDNS debugging is critical for both production cluster reliability and the CKA exam.
1. NetworkPolicy Mechanics & Default-Allow to Default-Deny Boundaries
By default, Kubernetes network communication is non-isolated (default-allow) : every Pod can communicate with every other Pod across all namespaces and worker nodes. +-----------------------------------------------------------------------------------------+
- | NETWORKPOLICY ISOLATION TRANSITION |
- | |
- | [DEFAULT STATE: NON-ISOLATED] |
- | - All Ingress traffic allowed from any source. |
- | - All Egress traffic allowed to any destination. |
- | | |
- | v (NetworkPolicy created selecting Pod) |
- | [ISOLATED STATE: DEFAULT-DENY] |
- | - If policyTypes includes 'Ingress': ALL incoming traffic is DENIED except whitelisted.|
- | - If policyTypes includes 'Egress': ALL outgoing traffic is DENIED except whitelisted. |
- +-----------------------------------------------------------------------------------------+
Important
CNI Plugin Policy Support Requirement: NetworkPolicies are API specifications enforced exclusively by the CNI plugin . If a cluster runs standard Flannel without network policy extensions, NetworkPolicy objects can be created in the API server, but no network traffic will ever be filtered or blocked . A CNI with native policy enforcement (e.g., Calico, Cilium, Antrea, Weave Net, or Canal) is mandatory.
2. The CoreDNS Egress Trap & Whitelisting Rule
The most frequent administrative failure when implementing an Egress NetworkPolicy is failing to whitelist internal DNS resolution on UDP/TCP port 53. If you isolate egress traffic without permitting DNS queries, the Pod cannot resolve any service name (including kubernetes.default ), causing all outbound network calls to time out. apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
- name: secure-app-policy
- namespace: production
spec:
podSelector:
matchLabels:
app: api-gateway
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
role: frontend
ports:
- protocol: TCP
- port: 8080
egress:
# Allow DNS to CoreDNS Pods in kube-system.
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- protocol: UDP
- port: 53
- protocol: TCP
- port: 53
- # --- ALLOW OUTBOUND TO DATABASE ---
- to:
- podSelector:
matchLabels:
app: postgres-db
ports:
- protocol: TCP
- port: 5432
- 3. AND vs. OR Logic in NetworkPolicy Rules
Misaligning list dashes ( - ) in NetworkPolicy YAML fundamentally alters evaluation logic: +-----------------------------------------------------------------------------------------+
- | NETWORKPOLICY SELECTOR LOGIC EVALUATION |
- | |
- | [EXAMPLE A: OR LOGIC (Two Separate List Items)] |
| ingress:
| - from:
- | - namespaceSelector: # Match ANY pod in namespace with label env=prod |
- | matchLabels: # OR |
- | env: prod # Match pods in LOCAL namespace with role=client |
- | - podSelector: |
- | matchLabels: |
- | role: client |
- | |
- | [EXAMPLE B: AND LOGIC (Single List Item with Multiple Selectors)] |
| ingress:
| - from:
- | - namespaceSelector: # Match ONLY pods with label role=client |
- | matchLabels: # INSIDE namespaces with label env=prod |
- | env: prod # (BOTH conditions must be satisfied) |
- | podSelector: |
- | matchLabels: |
- | role: client |
- +-----------------------------------------------------------------------------------------+
- Combining ipBlock , namespaceSelector , and podSelector
ipBlock : Specifies CIDR ranges (e.g., cidr: 10.0.0.0/16 , except: [10.0.1.0/24] ). Cannot be used to target cluster Pod IPs directly because Pod IPs are dynamic.
namespaceSelector : Selects entire namespaces based on namespace labels (e.g., kubernetes.io/metadata.name: kube-system ).
podSelector : Selects Pods based on Pod labels within the target namespace.
4. CoreDNS Architecture & Diagnostic Runbook
CoreDNS runs as a 2-replica Deployment in the kube-system namespace, exposed via a ClusterIP service (usually 10.96.0.10 in kubeadm clusters). +-----------------------------------------------------------------------------------------+
- | DNS RESOLUTION & /etc/resolv.conf |
- | |
- | [INSIDE POD: /etc/resolv.conf] |
- | nameserver 10.96.0.10 |
- | search default.svc.cluster.local svc.cluster.local cluster.local |
- | options ndots:5 |
- | |
- | QUERY RESOLUTION ORDER for 'backend-svc': |
- | 1. backend-svc.default.svc.cluster.local ---> SUCCESS (Returns ClusterIP) |
- | 2. backend-svc.svc.cluster.local ---> NXDOMAIN |
- | 3. backend-svc.cluster.local ---> NXDOMAIN |
- +-----------------------------------------------------------------------------------------+
- The ndots:5 Resolution Penalty
By default, Kubernetes configures /etc/resolv.conf with options ndots:5 . Any query with fewer than 5 dots (e.g., api.example.com has 2 dots) will first append the search domains ( default.svc.cluster.local , svc.cluster.local , cluster.local ) before querying the public root servers, generating 3 NXDOMAIN queries for every external lookup. In high-traffic workloads, using Fully Qualified Domain Names ending with a dot (e.g., api.example.com. ) bypasses search domain expansion.
- Diagnosing CoreDNS Outages: # 1. Check CoreDNS deployment and pod health
- kubectl get pods -n kube-system -l k8s-app=kube-dns -o wide
- # 2. Check CoreDNS logs for errors, forward timeouts, or crash loops
- kubectl logs -n kube-system -l k8s-app=kube-dns --tail=50
- # 3. Check CoreDNS Corefile ConfigMap
- kubectl get configmap coredns -n kube-system -o yaml
- # 4. Enable CoreDNS query logging for real-time inspection
- # Edit ConfigMap and add the 'log' plugin inside the Corefile block
- kubectl edit configmap coredns -n kube-system
The CoreDNS loop CrashLoopBackOff:
If CoreDNS pods are in CrashLoopBackOff with the log: plugin/loop: Loop (127.0.0.1:53 -> :53) detected for zone "."
Cause: Upstream DNS forward loop caused by systemd-resolved on the host node forwarding queries back to 127.0.0.53 .
Remediation: Keep the protective loop plugin. On systemd-resolved hosts, configure kubelet resolvConf (or --resolv-conf ) to use the real resolver file, commonly /run/systemd/resolve/resolv.conf ; kubeadm normally detects this. Alternatively configure CoreDNS forward to an approved non-looping upstream. Then restart CoreDNS and verify queries.
- 5. End-to-End DNS Verification Commands
- To verify DNS resolution from within a live workload: # Launch an ephemeral diagnostic container
- kubectl run dns-test --rm -it --image=busybox:1.36 --restart=Never -- /bin/sh
- # --- Inside test container ---
- # Test cluster-internal service resolution
- nslookup kubernetes.default
- nslookup backend-svc.production.svc.cluster.local
- # Test direct query against CoreDNS Service IP
- nslookup kubernetes.default 10.96.0.10
- # Test SRV record discovery for headless StatefulSet services
- nslookup -type=SRV cassandra-headless.default.svc.cluster.local
- # Test external Internet resolution
- nslookup google.com