Pod DNS Policy and dnsConfig
Two Pods in one cluster can resolve the same name differently, because their /etc/resolv.conf files differ. Where do the lines in that file come from, and how much of them can the Pod spec change?
Play the animation 6 steps, animated, plays on a computer or a tablet
Pod DNS Policy and dnsConfig, step by step
-
Pod web was created with dnsPolicy unset, so the API server defaulted it to ClusterFirst, not Default, before the Kubelet got the Pod from its API watch. The nameserver is the Kubelet clusterDNS, three cluster search domains come before the Node ones, and the Node options are dropped for ndots:5.
Play from step 1 -
With dnsPolicy Default the Kubelet copies the nameserver, search and options lines of the file its resolvConf setting names, /etc/resolv.conf by default. On systemd-resolved hosts it should name /run/systemd/resolve/resolv.conf, since the stub file can cause a forwarding loop.
Play from step 2 -
A Pod with hostNetwork true shares the network namespace of the Node. Left on ClusterFirst it quietly falls back to Default, so it gets the Node file, and cluster names resolve only if the Node resolver forwards the cluster domain to cluster DNS.
Play from step 3 -
To get the cluster file back, a host network Pod is given dnsPolicy ClusterFirstWithHostNet. The file then holds the cluster nameserver, the cluster search domains before the Node ones, and ndots:5, exactly as for a ClusterFirst Pod. Windows Nodes do not support this policy.
Play from step 4 -
With dnsPolicy None the Kubelet starts from an empty configuration and uses neither the Node file nor its cluster settings. Everything comes from dnsConfig, which must then list at least one nameserver, and its searches and options are written as given, minus duplicates.
Play from step 5 -
On the other policies dnsConfig merges on top. Its three nameservers are appended to the ClusterFirst one and then cut to the first 3 with a warning event, so 192.0.2.3 is dropped. Its searches are appended minus duplicates, so only lab.test is new, and ndots:2 replaces ndots:5 by name while edns0 is added.
Play from step 6