The symptoms rarely say "DNS". An application logs a timeout to a database that is up. One request in a hundred takes five seconds longer than the rest. A new namespace with a default-deny NetworkPolicy can't reach anything, including Services it is explicitly allowed to reach. A node is replaced and CoreDNS goes into CrashLoopBackOff.
Every one of these is a name resolution failure, each with a different cause somewhere between the application and the upstream resolver. Follow the query along its path and check each hop in order.
Who this is for: engineers debugging failed or slow lookups in a cluster that uses CoreDNS.
What you walk away with: a fixed sequence of checks from the pod outwards, a symptom-to-cause table, an explanation of what ndots:5 costs you, and the dnsConfig settings worth knowing.
The path of one query
- The application calls its resolver library (glibc, musl, Go's resolver, the JVM's).
- The library reads
/etc/resolv.confin the container, which the kubelet wrote. - It sends a UDP packet to the nameserver address there: the ClusterIP of the
kube-dnsService. - kube-proxy (or your CNI) rewrites that address to one CoreDNS pod.
- CoreDNS answers cluster names from its view of the API, and forwards everything else to an upstream resolver.
Stop at the first failing check.
Step 1: read the pod's resolv.conf
kubectl exec -it <pod> -- cat /etc/resolv.conf
With the default DNS policy you should see something like:
search prod.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.96.0.10
options ndots:5
The first search domain contains the pod's namespace. The nameserver should match the Service:
kubectl -n kube-system get service kube-dns
The Service is called kube-dns even though CoreDNS is behind it; the name and the k8s-app=kube-dns label were kept for backward compatibility.
If it shows the node's nameservers instead, check dnsPolicy. The value Default means "inherit from the node" and, despite its name, is not the default; ClusterFirst is. Pods with hostNetwork: true fall back to the node's configuration unless they set ClusterFirstWithHostNet.
If the image has no shell, read the file from the node or attach an ephemeral container with kubectl debug -it <pod> --image=<tools-image> --target=<container>.
Step 2: understand what ndots:5 does to your query
ndots:5 tells the resolver: if a name has fewer than five dots, try it with each search domain appended first, and only then as written.
That makes orders and orders.prod resolve. It also means a lookup of api.example.com (two dots) from a pod in namespace prod goes out as:
| # | Name queried | Answer |
|---|---|---|
| 1 | api.example.com.prod.svc.cluster.local |
NXDOMAIN |
| 2 | api.example.com.svc.cluster.local |
NXDOMAIN |
| 3 | api.example.com.cluster.local |
NXDOMAIN |
| 4 | api.example.com |
the address |
The CoreDNS query log on a v1.37 kind cluster showed this sequence from a glibc and a musl image alike, each name asked once for A and once for AAAA. That makes eight queries for one hostname, six of them bound to fail. With the two extra node search domains in the Kubernetes documentation's example it is twelve.
This becomes a failure when CoreDNS or the upstream is close to its limits, or when one of those packets is lost (step 8).
Three ways to reduce it, with their costs:
| Fix | Effect | Cost |
|---|---|---|
Trailing dot in the application config (api.example.com.) |
The name is treated as fully qualified; no search list | Not every library accepts it. Test per application. |
Lower ndots through dnsConfig (see the end) |
Names with at least that many dots are tried as written first | With ndots:2, orders.prod.svc goes to the upstream resolver first. glibc then falls back to the search list; musl does not, so the name fails there. Shorter names keep working. |
The CoreDNS autopath plugin |
CoreDNS follows the search path server-side and returns the first real answer | Requires pods verified in the kubernetes plugin, which watches all pods and uses more memory |
Step 3: test from inside the cluster
Don't test from your laptop or from the node; neither uses the pod's resolver configuration. The Kubernetes documentation provides a test pod with dig and nslookup:
kubectl apply -f https://k8s.io/examples/admin/dns/dnsutils.yaml
kubectl exec -it dnsutils -- nslookup kubernetes.default
That pod runs in default. If the failing workload is behind a NetworkPolicy or on a particular node, run the test pod in the same namespace and on the same node, or you are testing a different path.
Four queries separate the main failure classes:
# 1. Cluster name, fully qualified: CoreDNS and the kubernetes plugin
kubectl exec -it dnsutils -- dig +short kubernetes.default.svc.cluster.local.
# 2. External name: the forward path
kubectl exec -it dnsutils -- dig +short example.com.
# 3. Same query over TCP
kubectl exec -it dnsutils -- dig +tcp +short kubernetes.default.svc.cluster.local.
# 4. Straight to one CoreDNS pod, bypassing the Service
kubectl exec -it dnsutils -- dig +short kubernetes.default.svc.cluster.local. @<coredns-pod-ip>
| Result | Where to look |
|---|---|
| 1 fails, 4 works | Service, EndpointSlices, kube-proxy or the CNI (step 4) |
| 1 and 4 both fail from this pod, work from another namespace | NetworkPolicy (step 7) |
| 1 works, 2 fails | Upstream forwarders (step 6) |
| 1 works, 3 fails | TCP 53 is blocked; large answers will fail |
| All work, the application still fails | The application's resolver or its cache, or an intermittent problem (step 8) |
dig ignores the search list unless you pass +search; for a short name use dig +search orders or nslookup orders. Both tools bring their own resolver code, so they show what the DNS servers answer, not how the application's libc behaves.
Step 4: the Service and its endpoints
kubectl -n kube-system get endpointslice -l kubernetes.io/service-name=kube-dns
kubectl -n kube-system get pods -l k8s-app=kube-dns -o wide
No endpoints means no CoreDNS pod exists; unready pods are listed too, so check READY in the pod list. Endpoints that all sit on one node mean a single node failure takes out cluster DNS; spread the replicas and add a PodDisruptionBudget.
Step 5: CoreDNS pods and logs
kubectl -n kube-system logs -l k8s-app=kube-dns --tail=100
Look for three things.
A forwarding loop. A line like [FATAL] plugin/loop: Loop (127.0.0.1:52603 -> :53) detected for zone "." and a pod in CrashLoopBackOff. The loop plugin halts CoreDNS on purpose when it sees its own probe query come back. The usual cause is a node whose /etc/resolv.conf points at a local stub such as 127.0.0.53 from systemd-resolved: CoreDNS inherits that file and forwards to itself. The fix is on the kubelet: its resolvConf setting (the --resolv-conf flag) should point at the real file, /run/systemd/resolve/resolv.conf with systemd-resolved. kubeadm detects systemd-resolved and sets this itself.
Permission errors. CoreDNS needs to list and watch Services, EndpointSlices, namespaces and pods. If the system:coredns ClusterRole lost a rule, for example EndpointSlices after an old manifest was re-applied, a restarted pod logs failed to list *v1.EndpointSlice: … is forbidden and never becomes Ready: clients time out (the documentation shows SERVFAIL). Check with kubectl describe clusterrole system:coredns.
Nothing at all. Without the log plugin CoreDNS does not log queries; errors only logs processing failures. To see whether queries arrive, add log to the Corefile, limited to failures to keep the volume down:
log . {
class denial error
}
denial covers NXDOMAIN and empty answers, error covers SERVFAIL and REFUSED.
Step 6: the Corefile and the upstream
kubectl -n kube-system get configmap coredns -o yaml
kubeadm v1.37 deploys CoreDNS v1.14.6 and, for the cluster domain cluster.local, generates this Corefile. Yours may differ, so read your own:
.: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
}
What each line means when debugging:
| Plugin | What to know |
|---|---|
kubernetes |
Answers the cluster zone. ttl is the TTL of its answers: the plugin's default is 5 seconds, this manifest sets 30. |
forward . /etc/resolv.conf |
Everything else goes to the nameservers of the node the CoreDNS pod runs on. Upstreams are picked at random by default and health-checked; an upstream counts as down after 2 failed checks. The per-query read timeout defaults to 2 seconds. |
max_concurrent 1000 |
Above 1000 concurrent forwarded queries, new ones get REFUSED. |
cache 30 |
Caps cache time at 30 seconds. It never extends a longer TTL; shorter ones are raised to the 5-second minimum. The two disable lines switch off caching of cluster names. The Corefile in cluster/addons has a plain cache 30 without them. SERVFAIL answers are cached for 5 seconds unless configured otherwise. |
health, ready |
The liveness and readiness endpoints. lameduck 5s delays shutdown by 5 seconds while /health keeps answering. |
reload |
Picks up Corefile changes without a restart. Per the Kubernetes documentation a ConfigMap edit may take a minute or two to reach the pods. |
Because forward uses the node's resolver file, external resolution can differ per node. If external names fail intermittently, compare the resolver configuration of the nodes hosting CoreDNS, and query the upstreams directly from the test pod (dig example.com. @<upstream-ip>).
Step 7: NetworkPolicy
A default-deny egress policy blocks DNS like everything else. The pod can then reach the destinations you allowed but can't resolve their names.
Allow both protocols. DNS falls back to TCP when an answer doesn't fit in a UDP packet, so a UDP-only rule works until a large record set appears:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-dns
namespace: prod
spec:
podSelector: {}
policyTypes: ["Egress"]
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
Two caveats. The NetworkPolicy documentation says that when a Service address is rewritten, it is not defined whether that happens before or after policy processing; it can differ per network plugin and Service implementation. With kubeadm's manifests this makes no difference, because Service port and container port are both 53. If your DNS pods listen on another port, allow both. And with NodeLocal DNSCache the pod's first hop is a link-local address on the node, not a CoreDNS pod, so this selector no longer describes it. How to allow that address (often an ipBlock rule) depends on your CNI. More in a minimum viable NetworkPolicy.
Step 8: intermittent failures
When every check passes and lookups still fail or stall occasionally, check three things.
Lost UDP packets and conntrack. A DNS query to the Service address is rewritten by DNAT and tracked by conntrack on the node. The Kubernetes documentation for NodeLocal DNSCache names "conntrack races" and dropped UDP packets as a known source of DNS timeouts, and notes that UDP entries stay in the conntrack table until they time out (nf_conntrack_udp_timeout), so a busy node can fill it. A lost UDP query is not retried by the network; the client waits for its resolver timeout and retries.
For "conntrack races" that page links Kubernetes issue #56903, titled "DNS intermittent delays of 5s". The five seconds match glibc: resolv.conf(5) gives 5 seconds as the default resolver timeout, and says glibc sends the A and AAAA queries in parallel from the same socket. The explanation usually given in community write-ups, not checked against kernel sources for this article, is that the two packets race when conntrack creates the entry and one is dropped. glibc has the options single-request and single-request-reopen to change how the pair is sent; per the musl documentation, musl sends both in parallel and has no such option.
NodeLocal DNSCache addresses this by running a caching agent on every node. Pods query it on a link-local address, which according to the documentation avoids DNAT and connection tracking for that hop, and the agent's connections to CoreDNS can be upgraded to TCP. The costs: another DaemonSet to operate, NetworkPolicy rules to revisit, and one more cache in the path.
Negative caching. An NXDOMAIN can be cached too. If a client asks for a Service name before the Service exists, a CoreDNS with a plain cache 30 may keep answering NXDOMAIN for up to 30 seconds after it is created. The kubeadm Corefile above disables the cache for cluster names, but a NodeLocal DNSCache in front of it caches again, and application runtimes add their own caches. "It works when I restart the pod" points here.
Capacity. CoreDNS is a Deployment with a fixed replica count unless something scales it. The Kubernetes documentation describes the cluster-proportional-autoscaler for this; its example gives one replica per 256 cores or 16 nodes, whichever is more.
On the metrics endpoint (port 9153), watch coredns_dns_request_duration_seconds for latency, coredns_dns_responses_total by rcode for SERVFAIL and REFUSED, and coredns_forward_max_concurrent_rejects_total for the max_concurrent limit.
Symptom to cause
| Symptom | Likely cause | Check |
|---|---|---|
| Nothing resolves in one namespace | Default-deny egress without a DNS rule | Step 7 |
Nothing resolves in a hostNetwork pod |
dnsPolicy falls back to the node's resolver |
Step 1 |
| Short name fails, FQDN works | Wrong namespace, or a changed search list | Steps 1–2 |
| Cluster names work, external names fail | Upstream resolver, node firewall, forward target |
Step 6 |
| External names fail on some nodes only | Different node resolver configuration | Step 6 |
CoreDNS in CrashLoopBackOff, Loop ... detected |
Node resolv.conf points at a local stub |
Step 5 |
Timeouts, CoreDNS pods 0/1, forbidden in the log |
CoreDNS can't read the API (RBAC) | Step 5 |
| REFUSED under load | max_concurrent reached |
Steps 6, 8 |
| Occasional multi-second stalls | Lost UDP packets, conntrack | Step 8 |
| New Service not resolvable for a while after creation | Negative caching in CoreDNS, NodeLocal DNSCache or the runtime | Step 8 |
| Large answers fail, small ones work | TCP 53 blocked, or Alpine 3.17 or older (musl without TCP fallback) | Steps 3, 7 |
| Some node nameservers are ignored | glibc uses at most 3 nameservers, and the cluster takes one | Node resolv.conf |
The dnsConfig settings worth knowing
dnsConfig works with any dnsPolicy; with None it is required. Its nameservers (at most 3), searches and options are merged with what the policy generates. Kubernetes allows up to 32 search domains and 2048 characters in total.
Lowering ndots for a workload that mostly calls external names:
spec:
dnsConfig:
options:
- name: ndots
value: "2"
orders and orders.prod still go through the search list. For names like orders.prod.svc see the table in step 2: use the full orders.prod.svc.cluster.local in such workloads.
Set ndots per workload, deliberately. Changing it cluster-wide changes how every multi-label short name resolves.