Kubernetes - How to set DNS Policy at Cluster Level

2/13/2019

I am currently setting the 'dnsPolicy' configuration in the pod spec to 'Default' so that the pod can inherit the node's DNS configuration.

While this is good, it requires a re-build/re-deploy of the Docker container in order for the policy to effect and it is limited at the pod level.

Is there a similar policy that can be applied cluster-wide? Such that deployment of new pods onto the cluster will automatically inherit the nodes DNS configuration because of the cluster-wide policy?

-- Shazad
cluster-computing
dns
kubernetes
kubernetes-pod
resolution

1 Answer

2/13/2019

There isn't really a supported way to do this cluster-wide. One reason is that your coredns or kube-dns use dnsPolicy: Default and not the default dnsPolicy: ClusterFirst so changing it cluster-wide might affect your coredns/kube-dns pods.

There is, however a more complicated approach that you can use with Dynamic Admission Controllers. In particular, using a MutatingAdmissionWebhook that you can use to modify the pods with certain annotations to have dnsPolicy: Default. For example, Istio uses this to inject the Envoy sidecar. This is a good document that describes how to build your own MutatingAdmissionWebhook.

Similar question: https://serverfault.com/questions/928257/is-there-a-way-to-change-the-default-dnspolicy-without-modifying-every-podspec

-- Rico
Source: StackOverflow