<p>Is it possible to use a private DNS in Kubernetes? For example, an application needs to connect to an external DB by its hostname. The DNS entry, which resolves the IP, is deposited in a private DNS.</p>

<p>My AKS (Azure Kubernetes Service) is running on version 1.17 which already uses the new coreDNS.</p>

<p>My first try was to use that private DNS like on VM by configuring the /etc/resolve.conf file of the pods:</p>

<pre><code>dnsPolicy: "None"
  dnsConfig:
    nameservers:
      - 10.76.xxx.xxx
      - 10.76.xxx.xxx
    searches:
      - az-q.example.com
    options:
      - name: ndots
        value: "2"
</code></pre>

<p>Then I tried to use configmap to adjust the coreDNS:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: kube-dns
  namespace: kube-system
data:
  upstreamNameservers: |
    ["10.76.xxx.xxx", "10.76.xxx.xxx"]
</code></pre>

<p>But my pod is every time running in an error on deployment:</p>

<pre><code>$ sudo kubectl logs app-homepage-backend-xxxxx -n ingress-nginx
events.js:174
      throw er; // Unhandled 'error' event
      ^
Error: getaddrinfo ENOTFOUND az-q.example.com az-q.example.com:636
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
</code></pre>

<p>What am I missing?</p>

<p>Everyting depends on <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">dnsPolicy</a> you set in deployment configuration file of your application. </p>

<p>When  Pod’s dnsPolicy 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. </p>

<p><strong>1.</strong> Many 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 resolv.conf (With systemd-resolved, this is
    <code>/run/systemd/resolve/resolv.conf</code>). kubeadm (>= <strong>1.11</strong>) automatically
    detects systemd-resolved, and adjusts the kubelet flags accordingly.</p>

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

<p><strong>2.</strong>  Linux’s libc is impossibly stuck (see this bug from 2005) with
    limits of just 3 DNS nameserver records and 6 DNS search records.
    Kubernetes needs to consume 1 nameserver record and 3 search
    records. This means that if a local installation already uses 3
    nameservers or uses more than 3 searches, some of those settings
    will be lost. As a partial workaround, the node can run dnsmasq
    which will provide more nameserver entries, but not more search
    entries. You can also use kubelet’s <code>--resolv-conf</code> flag.</p>

<p><strong>3</strong>. Make sure that you are not using  Alpine version <strong>3.3</strong> or earlier as
    your base image, DNS may not work properly then.</p>

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