Debugging CoreDNS: When Kubernetes Service DNS Fails
Fast recall
Quick revision
Core answer
kube-system resolving *.svc.cluster.local for all pods. DNS failures usually manifest as UnknownHostException or random 50% failures (one CoreDNS pod unhealthy). Debug order: (1) kubectl exec pod -- nslookup kubernetes.default to verify DNS from a pod; (2) check CoreDNS pods healthy (kubectl get pods -n kube-system -l k8s-app=kube-dns); (3) check CoreDNS logs for errors; (4) validate /etc/resolv.conf in pod (correct nameserver + search domains); (5) check NetworkPolicy isn't blocking DNS (UDP/53 to kube-dns); (6) verify CoreDNS ConfigMap. Fix: scale CoreDNS replicas, enable NodeLocal DNSCache, tune pod ndots, check for upstream resolver issues.Whether you know that DNS is the most common intermittent-failure culprit and how to isolate it
Assuming 'service is unreachable' means networking broken, without checking DNS first; or restarting CoreDNS pods without reading logs
Explain `ndots: 5`, search domain expansion, NodeLocal DNSCache for scalability, NetworkPolicy egress rules for DNS, CoreDNS Corefile plugins, and the classic DNS intermittency caused by conntrack race on parallel DNS queries
Interview-ready guide
Interview answer
When I see 'networking seems broken' my first instinct is to verify DNS. In a Kubernetes cluster DNS is responsible for every service name resolution, and intermittent DNS issues are the single most common hidden cause of vague connectivity problems.
My first command
kubectl run dns-test --rm -it --image=busybox --restart=Never -- nslookup kubernetes.default.- If that fails, DNS is totally broken — CoreDNS down or unreachable; check kube-system pods and NetworkPolicy.
- If kubernetes.default works but my service name fails, it's a missing Service, wrong namespace, or label mismatch —
kubectl get svcanddescribeit. - If internal works but external doesn't, it's an upstream resolver issue — CoreDNS inherits the node's resolv.conf by default; check the VPC DNS or force an explicit upstream in the Corefile.
Check CoreDNS health
kubectl get pods -n kube-system -l k8s-app=kube-dns— any CrashLoopBackOff? Any pod at 100% CPU under load?kubectl logson CoreDNS pods with--previousif they've restarted — Corefile errors show up here.- Scale CoreDNS replicas immediately if CPU is pegged —
kubectl scale deploy coredns -n kube-system --replicas=5.
The classic Kubernetes DNS performance issues
ndots: 5default — every lookup with fewer than 5 dots goes through the search list, sogoogle.combecomes 4 queries. Lower ndots to 2 via pod dnsConfig for external-heavy services; cuts external DNS volume 5x.- The 5-second timeout — glibc sends A and AAAA in parallel on the same UDP socket and conntrack can race, dropping one and retransmitting after 5 seconds. Fixes are
single-request-reopenin pod dnsConfig or enabling NodeLocal DNSCache which uses TCP. - NodeLocal DNSCache is the standard scalability answer — a DaemonSet runs on every node with a local cache; pods hit the local cache first, CoreDNS sees only cache misses. Dramatically cuts load and eliminates conntrack races. Standard recommendation for clusters over 100 nodes.
NetworkPolicy is the production trap
- A strict default-deny egress policy without an explicit allow rule for UDP/53 to kube-dns breaks every pod in the namespace.
- The rule must allow both UDP and TCP port 53 to pods labeled
k8s-app: kube-dnsinkube-system. - Classic production incident: a security-hardening policy rolls out, all services start failing to resolve, the fix is a one-line NetworkPolicy addition but it takes hours to find without the runbook.
Essential alerting I put in place
- CoreDNS P99 request duration > 100ms for 5 minutes — CoreDNS is overloaded.
- CoreDNS cache hit ratio drops suddenly — upstream failures.
- At least 2 CoreDNS pods ready — less than 2 is an incident.
- A synthetic DNS probe pod doing nslookup every 15 seconds — page at >1% failure rate.
Production hardening
- At least 3 CoreDNS replicas with topology spread across AZs and PDB minAvailable 2.
- NodeLocal DNSCache enabled.
- Pod-level ndots and single-request-reopen tuning.
- Explicit NetworkPolicy allow-dns rule in every namespace that uses default-deny.
- Document the DNS runbook — this is the single highest-ROI runbook because DNS-induced incidents are frequent and misdiagnosed.
Debugging CoreDNS: When Kubernetes Service DNS Fails
Direct Answer
CoreDNS runs as a Deployment in kube-system resolving *.svc.cluster.local for all pods. DNS failures usually manifest as UnknownHostException or random 50% failures (one CoreDNS pod unhealthy). Debug order: (1) kubectl exec pod -- nslookup kubernetes.default to verify DNS from a pod; (2) check CoreDNS pods healthy (kubectl get pods -n kube-system -l k8s-app=kube-dns); (3) check CoreDNS logs for errors; (4) validate /etc/resolv.conf in pod (correct nameserver + search domains); (5) check NetworkPolicy isn't blocking DNS (UDP/53 to kube-dns); (6) verify CoreDNS ConfigMap. Fix: scale CoreDNS replicas, enable NodeLocal DNSCache, tune pod ndots, check for upstream resolver issues.
Common Mistakes & Pitfalls
Assuming 'service is unreachable' means networking broken, without checking DNS first; or restarting CoreDNS pods without reading logs
Check your understanding
Answer these without looking back at the article.
- What is NodeLocal DNSCache and when should you enable it?
- Why does the `ndots: 5` default amplify DNS query volume?
- How does the glibc parallel A/AAAA query cause a 5-second timeout, and how do you fix it?
- What NetworkPolicy rule must you add to allow DNS egress in a default-deny namespace?
Related interview prep categories
2Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.