Kubernetes Service DNS Resolution Mechanics via the CoreDNS Plugin
A deep dive into how the kubelet configures resolv.conf for Pods and how the CoreDNS kubernetes plugin resolves internal Service DNS records.
Curated by Vibe DevOps · approx. 505 words
Key Takeaways
- The kubelet automatically generates resolv.conf for each Pod, configuring the nameserver to point to the kube-dns ClusterIP and setting ndots:5 by default.
- CoreDNS operates on a plugin chain architecture where the kubernetes plugin watches Services and EndpointSlices to serve A records.
- The default ndots:5 setting forces short domain queries to traverse the entire search domain list sequentially before resolving externally.
- Kubernetes v1.37 officially announced the retirement of the legacy kube-dns project after CoreDNS has long served as the default standard.
From Original Source
resolv.conf Configuration and the CoreDNS Plugin Chain
When provisioning a Pod with the default ClusterFirst dnsPolicy, the kubelet populates the nameserver entries with the kube-dns Service ClusterIP—typically the 10th IP in the service CIDR block (e.g., 10.96.0.10). The kubelet also preconfigures search domains, including the Pod's namespace, svc.cluster.local, and cluster.local.
CoreDNS processes incoming DNS queries through a plugin chain determined at compile time. The kubernetes plugin watches Service resources to return ClusterIP addresses or EndpointSlice IPs for Headless Services. Queries that do not match the internal cluster.local zone are forwarded to upstream DNS servers via the forward plugin.
- The kubelet sets ndots:5 by default to support flexible resolution across domain name formats, ranging from same-namespace short names to SRV records.
- The loop plugin prevents upstream forwarding loops when CoreDNS runs with a Default dnsPolicy.
Vibe DevOps Editorial Commentary
Query Load Optimization and Operational Best Practices
DevOps Perspective: While the default ndots:5 configuration simplifies internal Service discovery, it frequently causes a storm of redundant queries to CoreDNS for external domain lookups. When an application container queries an external endpoint, the resolver sequentially attempts resolution against each search domain before finally issuing the query for the external FQDN.
For workloads primarily connecting to external endpoints or heavily relying on third-party APIs, SREs should consider tuning dnsConfig to lower the ndots threshold or appending a trailing dot to FQDNs. For specialized Pods that do not require internal service discovery, switching dnsPolicy to Default significantly offloads CoreDNS and cuts DNS resolution latency.
⚠️ Operational Caveats & Limitations
- This analysis is based on default cluster behavior provisioned via kubeadm on Kubernetes v1.37 and CoreDNS v1.14.6.
- Lowering the ndots value in dnsConfig requires careful testing to ensure compatibility with cross-namespace short-name Service calls.