Sub topic 8
How cluster DNS works
This chapter assumes you can use kubectl get, describe, logs, and exec. It also assumes you know what a Pod, a Deployment, and a namespace are, and that you know what an A record is. It builds on the Service from the earlier chapters, whose name web is what clients look up.
Why Pods need DNS
A Service has a stable virtual IP, but that IP is assigned by the cluster. Applications should not hard-code it. Instead they use a name such as web, and cluster DNS turns that name into the Service IP.
Cluster DNS is a Service-discovery system that runs inside the cluster. Most clusters use CoreDNS for it. CoreDNS runs as ordinary Pods in the kube-system namespace, and a Service named kube-dns gives those Pods one stable IP.
The lookup path
When a container resolves a name, several parts take part. The kubelet (the node agent) writes the cluster DNS address into each Pod's /etc/resolv.conf when it starts the Pod. The container's resolver sends queries to that address. CoreDNS watches the Kubernetes API for Services and EndpointSlices, so it can answer from current cluster state.
Notice that DNS traffic itself travels through a Service. The query to kube-dns depends on the same Service machinery you are debugging. If Service routing is broken cluster-wide, DNS can break too.
What CoreDNS answers
For a Service name, CoreDNS returns an A record that holds the Service's cluster IP. For names outside the cluster domain, it forwards the query to an upstream resolver, usually the node's own DNS configuration.
Try it with the web Service from the earlier example. Start a temporary Pod and query the full name:
kubectl run tmp-debug --rm -it --restart=Never --image=busybox:1.36 -- sh
# inside the Pod:
nslookup web.default.svc.cluster.localA healthy answer lists the DNS server address and then the Service's cluster IP as the Address. Compare that IP with the output of kubectl get service web. They should match.
What DNS proves and what it does not
A successful lookup shows only that the name exists and that CoreDNS is reachable. It says nothing about whether the Service has ready endpoints or whether traffic can reach a backend Pod. A Service with zero endpoints still resolves to its cluster IP, and the connection then fails or hangs.
This gives you a quick way to place a fault:
| Symptom | Likely layer |
|---|---|
| `nslookup` fails or times out | DNS, CoreDNS, or a network policy blocking DNS |
| `nslookup` works, connection refused or times out | Service, endpoints, ports, or network path |
| Short name fails, full name works | Search domains in `resolv.conf` or the wrong namespace |
Common errors at this layer
- Testing with the short name
webfrom a different namespace. The short name only resolves within the Pod's own namespace. - Assuming a working lookup means the application is healthy.
- Reading the node's DNS settings instead of the Pod's
/etc/resolv.conf. Pods use their own file. - Forgetting that a NetworkPolicy can block the Pod's traffic to CoreDNS.
The next chapters cover how names are built across namespaces, how resolv.conf shapes lookups, and how to check CoreDNS itself.
Exercise
From a debug Pod, nslookup web.default.svc.cluster.local returns the Service's cluster IP, but wget to that IP and port times out. Does this point to a DNS fault? What should you check next?
Show answer
No. DNS did its job, because the name resolved to the Service IP. The fault is further along the path. Check whether the Service has ready endpoints with kubectl get endpointslices -l kubernetes.io/service-name=web, then check that the Service selector matches the Pod labels and that targetPort matches the container's listening port.
Exercise
Why can a failure of the kube-dns Service affect name lookups even when the CoreDNS Pods are running?
Show answer
Pods send DNS queries to the kube-dns Service IP, not to the CoreDNS Pod IPs. If that Service has no endpoints or kube-proxy cannot route it, queries never reach CoreDNS.