Debug DNS Resolution Failures in Pods
Troubleshoot pods unable to resolve DNS names. Check CoreDNS health, ndots configuration, search domains, and NetworkPolicies blocking UDP port 53 DNS traffic.
π‘ Quick Answer: Test with
kubectl exec <pod> -- nslookup kubernetes.default. If it fails, check CoreDNS pods (kubectl get pods -n kube-system -l k8s-app=kube-dns), verify the Service ClusterIP (kubectl get svc kube-dns -n kube-system), and check if NetworkPolicies block UDP/TCP port 53.
The Problem
Pods canβt resolve DNS names β Service names, external domains, or both. Applications fail with βName or service not knownβ, βTemporary failure in name resolutionβ, or connection timeouts when using hostnames.
The Solution
Step 1: Test DNS from Inside a Pod
# Quick test β resolve the kubernetes API service
kubectl exec -it deploy/myapp -- nslookup kubernetes.default
# If this fails β cluster DNS is broken
# Test external resolution
kubectl exec -it deploy/myapp -- nslookup google.com
# If cluster DNS works but external fails β upstream DNS issue
# Use a debug pod if your containers don't have nslookup
kubectl run dns-test --image=busybox:1.36 --rm -it -- nslookup kubernetes.defaultStep 2: Check CoreDNS
# Are CoreDNS pods running?
kubectl get pods -n kube-system -l k8s-app=kube-dns
# NAME READY STATUS RESTARTS
# coredns-5d78c9869d-abc12 1/1 Running 0
# coredns-5d78c9869d-def34 1/1 Running 0
# Check CoreDNS logs for errors
kubectl logs -n kube-system -l k8s-app=kube-dns --since=5m
# Check the DNS Service ClusterIP
kubectl get svc kube-dns -n kube-system
# NAME TYPE CLUSTER-IP PORT(S)
# kube-dns ClusterIP 10.96.0.10 53/UDP,53/TCPStep 3: Check Pod DNS Configuration
# See what DNS config the pod has
kubectl exec myapp-pod -- cat /etc/resolv.conf
# nameserver 10.96.0.10 β Should point to kube-dns ClusterIP
# search myapp.svc.cluster.local svc.cluster.local cluster.local
# options ndots:5 β Important!Step 4: The ndots Problem
With ndots:5, any name with fewer than 5 dots is treated as a relative name. google.com (1 dot) triggers 4 search domain lookups BEFORE the absolute query:
google.com.myapp.svc.cluster.localβ NXDOMAINgoogle.com.svc.cluster.localβ NXDOMAINgoogle.com.cluster.localβ NXDOMAINgoogle.com.β SUCCESS
This adds latency. Fix with a trailing dot or lower ndots:
spec:
dnsConfig:
options:
- name: ndots
value: "2" # Reduce unnecessary search domain lookupsStep 5: Check NetworkPolicy
# If you have NetworkPolicies, DNS (port 53) must be allowed
kubectl get networkpolicy -n myapp
# Ensure egress allows DNS
# See: network-policy-debug-connectivity recipe for the allow-dns policyCommon Issues
CoreDNS CrashLooping
kubectl logs -n kube-system -l k8s-app=kube-dns --previous
# Common: "Loop detected" β CoreDNS is forwarding to itself
# Fix: check /etc/resolv.conf on the NODE (not pod) β ensure it doesn't point to the ClusterIPDNS Works for Services but Not External Names
CoreDNS upstream forwarder may be misconfigured:
kubectl get configmap coredns -n kube-system -o yaml
# Check the "forward" directive β should point to valid upstream DNS
# forward . /etc/resolv.conf β Uses node's DNS
# forward . 8.8.8.8 8.8.4.4 β Explicit upstreamBest Practices
- Lower ndots to 2 for pods that resolve many external names β reduces DNS queries by 3x
- Use FQDN with trailing dot in configs β
api.example.com.skips search domains entirely - Always allow DNS in NetworkPolicies β UDP+TCP port 53 to kube-dns
- Monitor CoreDNS β dashboard or
coredns_dns_request_count_totalmetric - Donβt use
dnsPolicy: Defaultunless you want node DNS instead of cluster DNS
Key Takeaways
nslookup kubernetes.defaultis the first test β if it fails, CoreDNS is down or unreachable- Check
/etc/resolv.confin the pod β nameserver should be the kube-dns ClusterIP ndots:5causes 4 extra lookups per external name β lower it for latency-sensitive apps- NetworkPolicies blocking port 53 is a common hidden cause
- CoreDNS logs reveal upstream failures, loop detection, and SERVFAIL causes

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 β