NetworkingLesson 5 of 8
- The pod network model, not reconciled
- Services, not reconciled
- EndpointSlices and kube-proxy, not reconciled
- Following a packet through the node, not reconciled
- Cluster DNS with CoreDNS, not reconciled
- Gateway API and the frozen Ingress API, not reconciled
- NetworkPolicies, not reconciled
- gRPC, service mesh and mTLS, not reconciled
Cluster DNS with CoreDNS
Every pod resolves names through CoreDNS and a search list the kubelet writes. Learn the names Kubernetes publishes, read a Corefile, cut the cost of ndots:5, and debug resolution from inside the cluster.
Shows the lesson one block at a time. Arrow keys step, number keys jump to a scene, and Escape returns to the page where you were.
Reconcile, in 7 scenes
Names
Kubernetes publishes a small, specified set of names. Anything else that happens to resolve is an implementation detail.
- Services.
<service>.<namespace>.svc.<cluster-domain>, withcluster.localas the usual cluster domain. A normal Service’s name resolves to its cluster IP. A headless Service’s name resolves to one address per ready pod. - Named ports. Each named port gets an SRV record,
_<port-name>._<protocol>.<service>.<namespace>.svc.<cluster-domain>. For a normal Service it answers with the port number and the Service’s name; for a headless Service, with one answer per pod. - Pods behind a headless Service. A pod that sets
hostnameandsubdomain, with a headless Service named like the subdomain in the same namespace, gets<hostname>.<subdomain>.<namespace>.svc.<cluster-domain>. StatefulSets set both fields for you, which is where names such asdb-0.db.shop.svc.cluster.localcome from. - Pods by address.
10-244-2-3.shop.pod.cluster.localresolves to10.244.2.3. It exists for compatibility and proves nothing about the pod.
Pods rarely type the full names, because the kubelet writes a search list into every pod’s /etc/resolv.conf.
kubectl -n shop exec toolbox -- cat /etc/resolv.conf
search shop.svc.cluster.local svc.cluster.local cluster.local nameserver 10.96.0.10 options ndots:5
kubectl -n shop exec toolbox -- nslookup ledger
Server: 10.96.0.10 Address: 10.96.0.10#53 ** server can't find ledger: NXDOMAIN command terminated with exit code 1
kubectl -n shop exec toolbox -- nslookup ledger.payments
Server: 10.96.0.10 Address: 10.96.0.10#53 Name: ledger.payments.svc.cluster.local Address: 10.100.96.72
ledger alone expands to ledger.shop.svc.cluster.local first, because the pod is in shop, and the Service lives in payments. ledger.payments matches through the second search domain. A name means different things in different namespaces, which is a feature for promoting the same configuration through environments and a trap when a client moves.
kubectl -n shop get pods -l app=db -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES db-0 1/1 Running 0 30s 10.244.3.2 kx-worker3 <none> <none> db-1 1/1 Running 0 20s 10.244.1.3 kx-worker <none> <none>
kubectl -n shop exec toolbox -- nslookup db
Server: 10.96.0.10 Address: 10.96.0.10#53 Name: db.shop.svc.cluster.local Address: 10.244.3.2 Name: db.shop.svc.cluster.local Address: 10.244.1.3
kubectl -n shop exec toolbox -- nslookup db-0.db
Server: 10.96.0.10 Address: 10.96.0.10#53 Name: db-0.db.shop.svc.cluster.local Address: 10.244.3.2
A headless answer changes whenever a pod comes or goes, and clients may cache it for the record’s TTL. A client that caches db for 30 seconds can keep dialling a pod that has already been replaced, so clients of headless Services should re-resolve when a connection fails, not only when the cache expires.
ExplainerName resolution in a pod
Podtoolbox10.244.3.4
/etc/resolv.conf
- search
- shop.svc.cluster.localsvc.cluster.localcluster.local
- nameserver
- 10.96.0.10
- options
- ndots:5
- ledger.shop.svc.cluster.localnot sent yet
- ledger.svc.cluster.localnot sent yet
- ledger.cluster.localnot sent yet
- ledgernot sent yet
CoreDNSkube-dns10.96.0.10
- kubernetes cluster.local in-addr.arpa ip6.arpaanswers cluster.local names from the API: authoritative
- forward . /etc/resolv.confsends everything else to the node's resolver at 172.18.0.1
No query sent yet.
Answer
Waiting for the resolver.
$ kubectl -n shop exec toolbox -- nslookup ledger Resolve the name to see what nslookup prints.
The name has no dots, fewer than ndots:5, so the resolver tries every search domain before the name as typed.
CoreDNS
CoreDNSThe DNS server most clusters run as the cluster DNS add-on: a Deployment in kube-system that answers for the cluster domain from data it watches in the API, and forwards other names upstream. runs behind a Service called kube-dns, and its pods carry the label k8s-app=kube-dns. Both names come from kube-dns, the server CoreDNS replaced, and are kept so that tools and network policies that select them still work.
Two kubelet settings connect pods to it: clusterDNS (--cluster-dns) becomes the nameserver line in each pod’s resolv.conf, and clusterDomain (--cluster-domain) builds the search list. They configure the pods’ resolvers, not CoreDNS. kubeadm and kind put the DNS Service at the tenth address of the Service range, 10.96.0.10; that address is a kubeadm convention, not a Kubernetes constant.
CoreDNS does not query the API server per lookup. It watches Services, EndpointSlices and namespaces and answers from memory, so its RBAC role must allow listing and watching EndpointSlices. It does not read the v1 Endpoints API, which has been deprecated since Kubernetes 1.33. A freshly created Service resolves once CoreDNS’s watch delivers it.
The Corefile
CoreDNS reads its configuration, the Corefile, from the coredns ConfigMap in kube-system.
kubectl -n kube-system get configmap coredns -o jsonpath='{.data.Corefile}'
.:53 {
errors
health {
lameduck 5s
}
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
ttl 30
}
prometheus :9153
forward . /etc/resolv.conf {
max_concurrent 1000
}
cache 30 {
disable success cluster.local
disable denial cluster.local
}
loop
reload
loadbalance
}.:53 is a server block for every zone on port 53. Inside it, each line enables a plugin:
errorslogs errors to standard output.healthserveshttp://localhost:8080/health.lameduck 5smakes a shutting-down pod report unhealthy but keep answering for five more seconds, while proxies remove it.readyserves port 8181 and returns 200 once every plugin that can signal readiness has; the readiness probe uses it.kubernetesanswers forcluster.localand the reverse zones from its watches.pods insecureanswers pod-address names without checking that the pod exists, for compatibility with kube-dns;pods verifiedchecks, andpods disabledturns them off.fallthroughpasses reverse lookups it cannot answer to the next plugin, andttlsets the TTL on its answers (5 seconds by default, at most 3600).prometheusexposes metrics on port 9153.forward . /etc/resolv.confsends every other name to the resolvers in the CoreDNS pod’s own resolv.conf, which come from the node, because CoreDNS runs withdnsPolicy: Default.max_concurrentcaps queries in flight upstream.cache 30caches answers for up to 30 seconds; this Corefile leavescluster.localout becausekubernetesalready answers it from memory.loopdetects a forwarding loop and stops CoreDNS.reloadreloads the Corefile when the ConfigMap changes; allow about two minutes.loadbalanceshuffles the order of A, AAAA and MX records in each answer.
A stub domain, a zone answered by a specific DNS server, is another server block that uses forward:
consul.local:53 {
errors
cache 30
forward . 10.150.0.1
}
forward needs addresses; CoreDNS does not accept a nameserver given as a hostname. CoreDNS has no in-tree response policy zone (RPZ) plugin, so DNS filtering needs an external plugin compiled into the image or a separate resolver.
dnsPolicy
spec.dnsPolicy decides where the kubelet takes a pod’s resolver settings from:
ClusterFirst, the default, uses cluster DNS, which forwards names outside the cluster domain upstream.Defaultinherits the node’s resolv.conf. Despite its name it is not the default, and cluster names do not resolve.ClusterFirstWithHostNetis for pods withhostNetwork: truethat need cluster names. A host-network pod withClusterFirstgets the node’s resolver instead.Noneignores both and takes everything fromdnsConfig.
dnsConfig adds to whatever the policy produced: up to 3 nameservers, up to 32 searches (at most 2048 characters in total), and options, which are merged by name.
kubectl -n shop get pod hostdns -o jsonpath='{.spec.dnsPolicy}'
Default
kubectl -n shop exec hostdns -- cat /etc/resolv.conf
nameserver 172.18.0.1 options ndots:0
kubectl -n shop exec hostdns -- nslookup ledger.payments.svc.cluster.local
Server: 172.18.0.1 Address: 172.18.0.1#53 ** server can't find ledger.payments.svc.cluster.local: NXDOMAIN command terminated with exit code 1
ndots:5 and search paths
The resolver in the pod decides when to use the search list. A name with fewer dots than ndots is tried with each search domain appended first, and only then as written. A name with at least ndots dots is tried as written first. A name ending in a dot is absolute and never searched.
Kubernetes sets ndots:5 so that the usual relative forms of cluster names go through the search list before they are tried as written: ledger.payments.svc has two dots and the SRV name _http._tcp.ledger.payments.svc has four, and neither exists outside the cluster domain.
External names pay for it. api.example.com has two dots, so a pod in shop asks for api.example.com.shop.svc.cluster.local, then api.example.com.svc.cluster.local, then api.example.com.cluster.local, then any search domains inherited from the node, and only then api.example.com. Each attempt but the last returns NXDOMAIN, and glibc sends an A and an AAAA query for every attempt, so one lookup typically costs 8 to 10 or more queries. Multiply that by every outbound call an application does not cache.
Three fixes, from narrowest to broadest:
- Absolute names. Configure
api.example.com.with the trailing dot. Some HTTP clients pass the dot on in theHostheader or TLS server name, which can break virtual hosting and certificate checks, so test it. - A lower
ndots. For a workload that mostly calls external names, set it indnsConfig. Names with fewer dots than the lowered value still use the search list first, and fully qualified cluster names resolve at once. A partly qualified name with enough dots, such asledger.payments.svcunderndots:2, is tried as written first, fails, and then resolves through the search list, one wasted query later. - A node-local cache, covered next, which makes the remaining queries cheap.
apiVersion: v1
kind: Pod
metadata:
name: api-client
spec:
containers:
- name: app
image: nicolaka/netshoot:v0.16
command: ["sleep", "infinity"]
dnsConfig:
options:
- name: ndots
value: "2"
- name: edns0
Scaling DNS
Every pod depends on cluster DNS, so it needs headroom and spread. kubeadm deploys two CoreDNS replicas. The cluster-proportional-autoscaler scales them with the cluster, in its linear mode to max(ceil(cores / coresPerReplica), ceil(nodes / nodesPerReplica)); its documented example uses 256 cores or 16 nodes per replica. Spread replicas across nodes and zones and protect them with a PodDisruptionBudget, so a drain never takes all of them.
NodeLocal DNSCacheA DaemonSet that runs a CoreDNS-based caching agent on every node, listening on a link-local address, so pods resolve through a cache on their own node. Stable since Kubernetes 1.18. removes most of the remaining cost. Pods’ queries reach a cache on their own node instead of travelling through the kube-dns cluster IP to a CoreDNS pod, which avoids the DNAT and conntrack path where UDP races drop queries and UDP entries fill the conntrack table. Cache misses for the cluster domain go on to CoreDNS over TCP, whose conntrack entries disappear when the connection closes. The agent listens on an address you choose that collides with nothing in the cluster, usually from the link-local range 169.254.0.0/16.
Dropped queries have a recognisable signature. A resolver retries a UDP query only after its timeout, five seconds by default in glibc, so DNS packet loss shows up as requests that take just over five seconds, while CPU-throttled CoreDNS replicas show up as latency that climbs with load. Both are reasons to run the cache.
The upstream manifest is a template. Before applying it, replace __PILLAR__LOCAL__DNS__ with the link-local address, __PILLAR__DNS__DOMAIN__ with the cluster domain, and __PILLAR__DNS__SERVER__ with the kube-dns Service IP, using the sed command on the NodeLocal DNSCache page. In kube-proxy’s iptables mode the agent also listens on the kube-dns Service IP, so pods need no change. IPVS mode uses a different substitution and also requires pointing the kubelet’s --cluster-dns at the link-local address.
Clusters still running kube-dns, the server CoreDNS replaced, should move: kube-dns is deprecated in Kubernetes 1.37, and no further packages are expected after v1.40.
Debugging
Work from the client outwards, and let the error tell you where to look:
- NXDOMAIN means a server answered that the name does not exist: a wrong name, a wrong namespace, or a policy such as
Defaultthat sends the query to the wrong server. connection timed out; no servers could be reachedmeans no server answered at all: CoreDNS is down or scaled to zero, thekube-dnsService has no endpoints, or a NetworkPolicy drops egress to port 53.- SERVFAIL means CoreDNS answered but could not resolve the name, usually because its upstream failed.
Break the server side and read the error a client gets. Deleting the CoreDNS pods costs a few seconds while their ReplicaSet replaces them; scaling CoreDNS to zero leaves kube-dns with no endpoints until someone scales it back. Between presses, run kubectl -n shop exec toolbox -- nslookup ledger.payments and watch the answer turn into a timeout.
Take CoreDNS away
- Runs kubectl -n kube-system delete pod -l k8s-app=kube-dns. Lookups time out until the CoreDNS ReplicaSet's new pods are ready.
- Runs kubectl -n kube-system scale deployment/coredns --replicas=0. Nothing scales it back: lookups time out until someone does.
Each button runs its command on the cluster. This line follows what happens next.
Start in the failing pod. cat /etc/resolv.conf shows the nameserver, search list and ndots it really uses. Then try nslookup kubernetes.default. If the image has no tools, use the upstream debugging pod: kubectl apply -f https://k8s.io/examples/admin/dns/dnsutils.yaml creates dnsutils, based on registry.k8s.io/e2e-test-images/agnhost:2.39. Base images matter: Alpine 3.17 and earlier ship a musl resolver without TCP fallback, so any answer larger than 512 bytes fails; Alpine 3.18 fixes it. glibc reads at most three nameservers, and Kubernetes needs one of them, so extra node nameservers are dropped.
Then check the server side.
kubectl -n kube-system get pods -l k8s-app=kube-dns -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES coredns-7dcd66b979-9xzmq 1/1 Running 0 60s 10.244.0.2 kx-control-plane <none> <none> coredns-7dcd66b979-fpcdz 1/1 Running 0 60s 10.244.0.3 kx-control-plane <none> <none>
kubectl -n kube-system get service kube-dns
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 60s
kubectl -n kube-system get endpointslices -l kubernetes.io/service-name=kube-dns
NAME ADDRESSTYPE PORTS ENDPOINTS AGE kube-dns-c4dck IPv4 53,53,9153 10.244.0.2,10.244.0.3 60s
kubectl -n kube-system logs deploy/coredns
Found 2 pods, using pod/coredns-7dcd66b979-9xzmq .:53 [INFO] plugin/reload: Running configuration SHA512 = 591cf328cccc12bc490481273e738df59329c62c0b729d94e8b61db9961c2fa5f046dd37f1cf888b953814040d180f52594972691cd6ff41be96639138a43908 CoreDNS-1.14.6 linux/amd64, go1.25.4,
Pods running, a Service at the address in resolv.conf, endpoints for UDP 53, TCP 53 and metrics, and clean logs: the server side is healthy, so look at the path between. If only one namespace times out, look for a NetworkPolicy there that isolates egress without allowing UDP and TCP 53 to the k8s-app=kube-dns pods in kube-system. To see whether queries arrive at all, add the log plugin to the Corefile for a few minutes; every query then appears in the CoreDNS logs.
A node-level problem can show up as CoreDNS crashing. On distributions that use systemd-resolved, the node’s resolv.conf points at a local stub such as 127.0.0.53; CoreDNS inherits it, forwards to itself, and the loop plugin stops it. Point the kubelet’s --resolv-conf at /run/systemd/resolve/resolv.conf, which kubeadm detects and does for you.
kubectl --context kind-kx run dnsutils --image=nicolaka/netshoot:v0.16 -- sleep infinitykubectl --context kind-kx wait --for=condition=Ready pod/dnsutils --timeout=60skubectl --context kind-kx exec dnsutils -- cat /etc/resolv.confkubectl --context kind-kx exec dnsutils -- nslookup kubernetes.defaultkubectl --context kind-kx exec dnsutils -- nslookup -type=srv _https._tcp.kubernetes.default.svc.cluster.localkubectl --context kind-kx exec dnsutils -- nslookup 10-96-0-1.default.pod.cluster.localkubectl --context kind-kx -n kube-system get configmap coredns -o yamlkubectl --context kind-kx -n kube-system get endpointslices -l kubernetes.io/service-name=kube-dnskubectl --context kind-kx delete pod dnsutils
For your own kind cluster kx: copy a command and paste it into your terminal. Run in the simulator runs the same command in this page's simulated cluster instead; nothing on this page touches your machine. The SRV answer carries port 443 and the name kubernetes.default.svc.cluster.local, because the kubernetes Service names its port https. The pod-address name resolves although no pod has that address: pods insecure does not check.
Actual state
Check your understanding
Your first answer to each check is the one that counts. After a miss you can answer again; passing every check reconciles the lesson.
Lesson not yet reconciled
Desired: 5 objectives, 0 metReconciled: 5 of 5 objectives met
- Write the DNS names of a Service, of a pod behind a headless Service, and of a named port's SRV record. (not yet met)
- Read a Corefile and say what each plugin in the default configuration does. (not yet met)
- Choose a dnsPolicy and dnsConfig for a pod, including pods on the host network. (not yet met)
- Cut the query load that ndots:5 causes with absolute names, dnsConfig and NodeLocal DNSCache. (not yet met)
- Diagnose a resolution failure from a debug pod, telling NXDOMAIN, timeouts and server failures apart. (not yet met)
Pass every check above to reconcile this lesson.
Every check has passed, so the desired state is met. First-try accuracy: 0 of 6. This lesson's review cards are in your queue.
Practice
Put this lesson to work on the simulated cluster. Everything runs in your browser, with nothing to install.
Changed since the notes
This lesson draws on an earlier set of study notes. Where the documentation contradicts a claim in them, qualifies it or has moved past it, the claim is listed here with the corrected statement and the source it was checked against.
Show 10 corrections
The notes saidEnable NodeLocal DNS Cache add-on
CorrectedNodeLocal DNSCache isn't an EKS add-on (neither AWS nor community). Deploy it from the upstream Kubernetes manifest (nodelocaldns.yaml) or a Helm chart.
The notes saidCluster DNS is often at 10.96.0.10
Corrected10.96.0.10 is the kubeadm default. Unless you set a custom service CIDR at creation, EKS assigns 10.100.0.0/16 or 172.20.0.0/16, so DNS is at 10.100.0.10 or 172.20.0.10.
The notes saidCoreDNS watches Services and Endpoints
CorrectedCoreDNS watches EndpointSlices. The Endpoints API is deprecated in Kubernetes 1.33.
The notes saidkubectl apply -f the nodelocaldns.yaml from master
CorrectedFirst substitute _PILLARLOCALDNS, _PILLAR_DNSDOMAIN_ and _PILLARDNSSERVER_ with sed. IPVS mode uses a different substitution and also changes kubelet --cluster-dns.
Sourcekubernetes.io/docs/tasks/administer-cluster/nodelocaldns
The notes saidCoreDNS is a managed EKS add-on maintained by AWS
CorrectedTrue. The add-on supports autoScaling configuration values (enabled, minReplicas, maxReplicas). nodesPerReplica and cpuCoresPerReplica need a minimum add-on build, for example v1.14.3-eksbuild.16 on 1.35/1.36.
Sourcedocs.aws.amazon.com/eks/latest/userguide/coredns-autoscaling.html
The notes saidDefault CoreDNS resources 100m/70Mi (limit 170Mi), cache 30, max_concurrent 1000
CorrectedNot confirmed for current EKS add-on builds. Check aws eks describe-addon-configuration and the live Corefile for the installed version.
Sourcedocs.aws.amazon.com/eks/latest/userguide/coredns-autoscaling.html
The notes saidUse busybox nslookup for DNS testing
CorrectedThe Kubernetes docs use a dnsutils pod based on registry.k8s.io/e2e-test-images/agnhost:2.39. They warn about musl DNS issues in Alpine 3.17 and earlier, not about busybox.
Sourcekubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution
The notes saidStub domains are configured via kubelet clusterDNS/clusterDomain
CorrectedThose kubelet fields set the pod's nameserver and search domain. Stub domains are Corefile server blocks that use forward.
Sourcekubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers
The notes saidRPZ example 'rpm { zone … }'
Corrected'rpm' is a typo, and CoreDNS has no in-tree rpz plugin.
The notes saidFour DNS queries per external resolution
CorrectedWith ndots:5, the resolver tries every search domain (three cluster domains plus node domains) before the absolute name, and glibc sends both A and AAAA for each. That is typically 8-10 or more queries.
Sourcekubernetes.io/docs/concepts/services-networking/dns-pod-service
Every correction across the guide, by note and topic.
Sources
Checked against kubernetes.io and AWS documentation for Kubernetes 1.37 on .
- kubernetes.io/docs/concepts/services-networking/dns-pod-service
- kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers
- kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution
- kubernetes.io/docs/tasks/administer-cluster/nodelocaldns
- kubernetes.io/docs/tasks/administer-cluster/dns-horizontal-autoscaling
- kubernetes.io/blog/2026/08/26/kubernetes-v1-37-release
- docs.aws.amazon.com/eks/latest/userguide/managing-coredns.html
- docs.aws.amazon.com/eks/latest/userguide/coredns-autoscaling.html
- docs.aws.amazon.com/eks/latest/best-practices/scale-cluster-services.html
- docs.aws.amazon.com/vpc/latest/userguide/amazon-vpc-limits.html
Cluster DNS with CoreDNS
↓ ↑ step, 1 to 7 scene, Esc leave