Interview Prep/Kubernetes/Services, DNS, Ingress and NetworkPolicy

DNS lookups occasionally take exactly 5 seconds, then succeed.

AdvancedTroubleshootingServices, DNS, Ingress and NetworkPolicy
Answer

Likely causes → The Linux conntrack race on parallel UDP A and AAAA queries sent from the same socket: one packet is dropped and glibc waits the full 5s timeout before retrying. Also seen when one CoreDNS replica is unhealthy but still in endpoints.

Diagnose →

kubectl exec web-x -- sh -c 'for i in $(seq 1 50); do /usr/bin/time -f %e getent hosts orders >/dev/null; done' 2>&1 | sort -n | tail
# On the node
sudo conntrack -S | grep insert_failed

Fix → Deploy NodeLocal DNSCache (Pods talk to a node-local IP and upstream uses TCP), or add single-request-reopen to dnsConfig.options for glibc-based images.

Prevent → NodeLocal DNSCache as a cluster default; monitor CoreDNS latency (coredns_dns_request_duration_seconds).

All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Services, DNS, Ingress and NetworkPolicy