Short answer: CoreDNS is up, but the path before or after it is broken
A Running CoreDNS pod only means the process is alive. A lookup travels pod → kube-dns Service → CoreDNS → upstream DNS, and the cause is usually one of four:
- A NetworkPolicy blocks port 53 — fails only in certain namespaces
- ndots:5 and search domains — only external names are slow or resolve oddly
- The upstream (forward) does not answer — cluster names work, external names get SERVFAIL
- The node path, such as node-local-dns — fails only for pods on certain nodes
Same problem, different message per runtime
- Go:
lookup orders on 10.96.0.10:53: no such host·read udp 10.244.1.7:43120->10.96.0.10:53: i/o timeout - nslookup / dig:
;; connection timed out; no servers could be reached·status: SERVFAIL - Python:
Temporary failure in name resolution· Node.js:getaddrinfo EAI_AGAIN· Java:UnknownHostException
30-second diagnosis: query kube-dns directly from the failing pod
NetworkPolicy applies by pod label, so do not test from a fresh pod; attach a debug container to the failing pod and query from there.
kubectl -n kube-system get svc kube-dns # CLUSTER-IP, e.g. 10.96.0.10
kubectl debug -it checkout-7d9f8-x2k1p -n shop --image=registry.k8s.io/e2e-test-images/jessie-dnsutils:1.3 -- sh
cat /etc/resolv.conf
dig @10.96.0.10 kubernetes.default.svc.cluster.local +short
dig @10.96.0.10 example.com +short
search shop.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.96.0.10
options ndots:5
- Both time out → blocked between the pod and CoreDNS (cause 1 or 4)
- Cluster name works, external name gets SERVFAIL → upstream (cause 3)
- Both work but the app is slow → ndots (cause 2)
Cause 1: a NetworkPolicy blocks DNS
A default-deny egress policy that opens the app's ports but forgets DNS is a common slip. Open both UDP and TCP 53 to the CoreDNS pods in kube-system. Leave out TCP and only queries with large responses fail.
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- { protocol: UDP, port: 53 }
- { protocol: TCP, port: 53 }
Cause 2: ndots:5 and search domains
A name with fewer than five dots, like api.example.com, is tried with each search domain first, starting with api.example.com.shop.svc.cluster.local, and the real name is asked last. Add a trailing dot (api.example.com.) or lower ndots in the pod's dnsConfig.
dnsConfig:
options:
- name: ndots
value: "2"
Cause 3: upstream and recursion
CoreDNS answers only cluster.local itself. It does not do recursive resolution for other names; the forward plugin hands them to an upstream resolver. The default forward . /etc/resolv.conf follows the node's resolv.conf.
kubectl -n kube-system logs -l k8s-app=kube-dns --tail=50
[ERROR] plugin/errors: 2 api.example.com. A: read udp 10.244.0.5:46012->10.0.0.2:53: i/o timeout
If the node's resolv.conf points to 127.0.0.53 (systemd-resolved), CoreDNS forwards to itself in a loop; the loop plugin logs [FATAL] plugin/loop: Loop ... detected and CoreDNS restarts. Point the kubelet's resolvConf at /run/systemd/resolve/resolv.conf, or put real upstream IPs in forward.
Cause 4: node-local-dns and the node path
With NodeLocal DNSCache, the nameserver in resolv.conf is a node-local address (often 169.254.20.10). If only one node fails, check the k8s-app=node-local-dns pod on that node. Lookups that are intermittently slow by exactly five seconds are a known symptom of a UDP conntrack race (parallel A and AAAA queries).
What not to do
- Restarting CoreDNS first — if the path is the problem, nothing changes.
- Deleting the whole egress policy — open DNS on 53 only.
The order to work in
- From the failing pod, run
dig @kube-dns-IPfor a cluster name and an external name - Both time out → NetworkPolicy (UDP and TCP 53), node-local-dns
- Only external names get SERVFAIL → Corefile
forwardand CoreDNS logs - Only slow → ndots and FQDNs
To practise the same situation as a problem, start with NetworkPolicy allows the app service but blocks CoreDNS resolution.
Quick diagnostic checklist
- Get the CLUSTER-IP with
kubectl -n kube-system get svc kube-dns. - Query from the failing pod with
kubectl debug, not from a fresh pod. - Read nameserver, search and ndots in the pod's
/etc/resolv.conf. - Run
dig @kube-dns-IPfor a cluster name and an external name and compare. - If both time out, check that NetworkPolicy allows UDP and TCP 53 to kube-system.
- If only external names get SERVFAIL, check the Corefile
forwardand upstream errors in CoreDNS logs. - If CoreDNS logs show
plugin/loop, check whether the node's resolv.conf points to 127.0.0.53. - If only one node fails, check the node-local-dns pod on that node.