Fix CoreDNS Resolution Failures in Kubernetes
Debug DNS resolution failures in Kubernetes pods. Covers CoreDNS crashes, NXDOMAIN errors, ndots configuration, and upstream DNS timeouts.
π‘ Quick Answer: DNS failures in pods usually come from CoreDNS pods being down, misconfigured
resolv.conf, or upstream DNS timeouts. Test withkubectl exec <pod> -- nslookup kubernetes.default. If it fails, check CoreDNS pods and logs inkube-system.Gotcha: The default
ndots:5setting causes ALL short names to try 5 search domain suffixes before querying the actual name. This adds latency and load. Setndots:2for most workloads.
The Problem
$ kubectl exec myapp-abc123 -- nslookup google.com
;; connection timed out; no servers could be reached
# Or
$ kubectl exec myapp-abc123 -- curl https://api.example.com
curl: (6) Could not resolve host: api.example.comThe Solution
Step 1: Test DNS Inside the Pod
# Test cluster DNS
kubectl exec myapp-abc123 -- nslookup kubernetes.default
# Test external DNS
kubectl exec myapp-abc123 -- nslookup google.com
# Check resolv.conf
kubectl exec myapp-abc123 -- cat /etc/resolv.conf
# nameserver 10.96.0.10 (CoreDNS ClusterIP)
# search default.svc.cluster.local svc.cluster.local cluster.local
# options ndots:5Step 2: Check CoreDNS
# Are CoreDNS pods running?
kubectl get pods -n kube-system -l k8s-app=kube-dns
# Check CoreDNS logs
kubectl logs -n kube-system -l k8s-app=kube-dns --tail=50
# Is the CoreDNS service reachable?
kubectl get svc -n kube-system kube-dnsStep 3: Fix Common Issues
CoreDNS pods crashing:
# Check for OOM or config errors
kubectl describe pods -n kube-system -l k8s-app=kube-dns
# Increase memory if OOMKilled
kubectl edit deployment coredns -n kube-system
# Set resources.limits.memory to 256Mi or higherSlow external DNS (ndots issue):
# Pod spec β reduce ndots for external-heavy workloads
spec:
dnsConfig:
options:
- name: ndots
value: "2"With ndots:5 (default), resolving api.example.com tries:
api.example.com.default.svc.cluster.localβ NXDOMAINapi.example.com.svc.cluster.localβ NXDOMAINapi.example.com.cluster.localβ NXDOMAINapi.example.comβ SUCCESS
Thatβs 3 wasted queries per lookup.
NetworkPolicy blocking DNS:
# Ensure DNS egress is allowed
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-dns
spec:
podSelector: {}
policyTypes: ["Egress"]
egress:
- to:
- namespaceSelector: {}
podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53graph TD
A[DNS Failure] --> B{nslookup kubernetes.default}
B -->|Fails| C{CoreDNS pods running?}
C -->|No| D[Fix CoreDNS deployment]
C -->|Yes| E[Check NetworkPolicy]
B -->|Works for cluster, fails external| F{Check CoreDNS upstream config}
F -->|Upstream timeout| G[Fix upstream DNS or forwarders]
F -->|NXDOMAIN| H[Check ndots and search domains]Common Issues
DNS works from some pods but not others
NetworkPolicy in that namespace is blocking UDP/53 egress. Add a DNS egress rule.
DNS slow but eventually resolves
Classic ndots:5 issue. Every external name tries cluster suffixes first. Set ndots:2.
DNS resolution races (intermittent failures)
Known Linux conntrack race condition with UDP DNS. Fix: enable dnsPolicy: Default for host-network pods, or use TCP for DNS queries.
Best Practices
- Set
ndots:2for workloads that primarily resolve external domains - Use FQDN with trailing dot (
api.example.com.) to skip search domain expansion entirely - Monitor CoreDNS metrics:
coredns_dns_requests_total,coredns_dns_responses_rcode_total - Always allow DNS egress in NetworkPolicies β itβs easy to forget
Key Takeaways
- Check CoreDNS pods first β if theyβre down, nothing resolves
ndots:5causes 3-4 wasted queries per external lookup β reduce for most workloads- NetworkPolicies must explicitly allow UDP/53 egress to CoreDNS
- Use
nslookup kubernetes.defaultto test cluster DNS vs external DNS separately

Recommended
Kubernetes Recipes β The Complete Book100+ production-ready patterns with detailed explanations, best practices, and copy-paste YAML. Everything in one place.
Get the Book βLearn by Doing
CopyPasteLearn β Hands-on Cloud & DevOps CoursesMaster Kubernetes, Ansible, Terraform, and MLOps with interactive, copy-paste-run lessons. Start free.
Browse Courses β