How does DNS work in Kubernetes?
Quick Answer
CoreDNS runs in the cluster and gives every Service a DNS name. Pods resolve names like my-svc.my-namespace.svc.cluster.local to the Service's ClusterIP; a search-domain list lets you use short names within a namespace.
Detailed Answer
CoreDNS (a DaemonSet/Deployment in kube-system, fronted by a Service usually at a fixed ClusterIP) is the cluster's resolver. Each Service gets an A/AAAA record at <service>.<namespace>.svc.cluster.local pointing to its ClusterIP; headless Services instead return the individual pod IPs, and StatefulSet pods get stable per-pod names. The kubelet configures each pod's /etc/resolv.conf to point at CoreDNS and adds search domains (<namespace>.svc.cluster.local, svc.cluster.local, cluster.local) so within a namespace you can just use 'my-svc' and within the cluster 'my-svc.other-ns'. Practical gotchas: a NetworkPolicy that blocks egress to CoreDNS (UDP/TCP 53 in kube-system) breaks all name resolution; ndots:5 in the search config can cause extra lookups for external names; and CoreDNS scaling/caching matters under heavy service-discovery load.
Code Example
kubectl -n kube-system get svc kube-dns # CoreDNS ClusterIP kubectl exec -it web -- cat /etc/resolv.conf # search domains + nameserver kubectl exec -it web -- nslookup my-svc.other-ns # cross-namespace lookup
Interview Tip
Name CoreDNS, the FQDN pattern (svc.ns.svc.cluster.local), and the killer failure mode: 'a default-deny egress policy without a DNS allow breaks resolution cluster-wide.' That trio shows depth.