<p>Im about to deploy a new K8S baremetal cluster using KubeSpray.
On on my agents, I have resolvd running that does not take the DNS settings from <code>/etc/resolvd.conf</code> but rather takes it from <code>/etc/systemd/resolved.conf</code>.</p>

<p>So which is the best DNS setting to use ? CoreDNS ? KubeDNS ? Just want to make sure that the pods I deploy use the same DNS servers as configured on my agent nodes.</p>

<p>whats should be my selection for</p>

<pre><code># Can be dnsmasq_kubedns, kubedns, coredns, coredns_dual, manual or none
dns_mode: kubedns
# Set manual server if using a custom cluster DNS server
#manual_dns_server: 10.x.x.x

# Can be docker_dns, host_resolvconf or none
resolvconf_mode: docker_dns
</code></pre>

<p>?</p>

<p>As per <a href="https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/#introduction" rel="nofollow noreferrer">official documentation</a>:</p>

<p>As of Kubernetes v1.12, <strong>CoreDNS is the recommended DNS Server, replacing kube-dns</strong>. However, kube-dns may still be installed by default with certain Kubernetes installer tools. Refer to the documentation provided by your installer to know which DNS server is installed by default.</p>

<p>The CoreDNS Deployment is exposed as a Kubernetes Service with a static IP. Both the CoreDNS and kube-dns Service are named  <code>kube-dns</code>  in the  <code>metadata.name</code>  field. This is done so that there is greater interoperability with workloads that relied on the legacy  <code>kube-dns</code>  Service name to resolve addresses internal to the cluster. It abstracts away the implementation detail of which DNS provider is running behind that common endpoint.</p>

<p>If a Pod’s  <code>dnsPolicy</code>  is set to “<code>default</code>”, it inherits the name resolution configuration from the node that the Pod runs on. The Pod’s DNS resolution should behave the same as the node. But see  <a href="https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/#known-issues" rel="nofollow noreferrer">Known issues</a>.</p>

<p>If you don’t want this, or if you want a different DNS config for pods, you can use the kubelet’s  <code>--resolv-conf</code>  flag. Set this flag to “” to prevent Pods from inheriting DNS. Set it to a valid file path to specify a file other than  <code>/etc/resolv.conf</code>  for DNS inheritance.</p>

<p><a href="https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/#known-issues" rel="nofollow noreferrer">Known Issue</a>:</p>

<p>Some Linux distributions (e.g. Ubuntu), use a local DNS resolver by default (systemd-resolved). Systemd-resolved moves and replaces  <code>/etc/resolv.conf</code>  with a stub file that can cause a fatal forwarding loop when resolving names in upstream servers. This can be fixed manually by using kubelet’s  <code>--resolv-conf</code>  flag to point to the correct  <code>resolv.conf</code>(With  <code>systemd-resolved</code>, this is  <code>/run/systemd/resolve/resolv.conf</code>). kubeadm 1.11 automatically detects  <code>systemd-resolved</code>, and adjusts the kubelet flags accordingly.</p>

<p>Kubernetes installs do not configure the nodes’  <code>resolv.conf</code>  files to use the cluster DNS by default, because that process is inherently distribution-specific. This should probably be implemented eventually.</p>

<p>Linux’s libc is impossibly stuck (<a href="https://bugzilla.redhat.com/show_bug.cgi?id=168253" rel="nofollow noreferrer">see this bug from 2005</a>) with limits of just 3 DNS  <code>nameserver</code>  records and 6 DNS  <code>search</code>  records. Kubernetes needs to consume 1  <code>nameserver</code>record and 3  <code>search</code>  records. This means that if a local installation already uses 3  <code>nameserver</code>s or uses more than 3  <code>search</code>es, some of those settings will be lost. As a partial workaround, the node can run  <code>dnsmasq</code>  which will provide more  <code>nameserver</code>  entries, but not more  <code>search</code>  entries. You can also use kubelet’s  <code>--resolv-conf</code>  flag.</p>

<p>If you are using Alpine version 3.3 or earlier as your base image, DNS may not work properly owing to a known issue with Alpine. Check  <a href="https://github.com/kubernetes/kubernetes/issues/30215" rel="nofollow noreferrer">here</a>  for more information.</p>
