nslookup from inside a pod and kubernetes.default fails while google.com still resolves, the pod can reach some DNS server but not the cluster DNS. This typically happens because of one file and one setting: /etc/resolv.conf inside the pod and the pod’s dnsPolicy.
Example failure:
Why this happens
Every pod has its own/etc/resolv.conf. Kubernetes (kubelet) writes that file for the pod based on the pod’s dnsPolicy and whether the pod uses the host network. A typical pod’s /etc/resolv.conf contains three important parts:
nameserver— usually the cluster DNS (kube-dns/CoreDNS) service IP.search— includes the pod’s namespace,svc, andcluster.localso short service names expand correctly.options— e.g.,ndotsvalue.
/etc/resolv.conf inside a normal pod:
nameserver points to the node’s DNS (the node’s /etc/resolv.conf) rather than the cluster DNS, the pod will resolve internet names but not Kubernetes service names. That happens when the pod will inherit the node resolver instead of using cluster DNS.
The culprit: dnsPolicy
Kubernetes exposesdnsPolicy on pods to control how DNS is configured. Common values:
ClusterFirst(default for most pods): kubelet configures/etc/resolv.confto use the cluster DNS so pods can resolve internal service names such askubernetes.default.Default: the pod inherits the node’s DNS configuration (the node’s/etc/resolv.conf). This allows internet name resolution via the node, but internal Kubernetes service names will not be resolved by that DNS.ClusterFirstWithHostNet: special policy for host-networked pods that still directs DNS to the cluster DNS.
The
Default dnsPolicy is misleading: it does not mean “use the Kubernetes default behavior.” It means “use the node’s resolver.” If you need cluster DNS resolution, do not use dnsPolicy: Default.Host networking adds a wrinkle
WhenhostNetwork: true is set, the pod uses the node’s network namespace. By default kubelet adjusts the dnsPolicy to ClusterFirstWithHostNet for these pods so they still use cluster DNS. Problems arise when dnsPolicy is explicitly set to Default on a host-networked pod — such pods will use the node resolver and lose ability to resolve cluster service names.
Host-networked pod that will run into the DNS problem:
ClusterFirstWithHostNet:
How to debug this issue
- Check
/etc/resolv.confinside the pod:
nameserver— is it the cluster DNS IP (e.g.,10.96.0.10) or the node IP?search— does it include<namespace>.svc.cluster.localandcluster.local?options ndots— ensure it’s reasonable (commonlyndots:5).
- Inspect the pod spec:
spec.dnsPolicy and spec.hostNetwork.
- If the pod uses host networking, ensure
dnsPolicyisClusterFirstWithHostNet(unless you intentionally want node DNS).
Quick checklist
References
Use the checklist above to quickly identify whether a pod is pointed at the node resolver by mistake, and updatednsPolicy or the pod spec accordingly to restore cluster DNS resolution.