<p>Im overriding the the dns policy of a pod since I'm facing a <a href="https://stackoverflow.com/questions/63719383/pod-unable-to-install-packagesapt-get-update-or-apt-get-install">issue</a> with default <code>/etc/resolv.conf</code> of the pod. Another issue is that the pod is not able to connect to smtp server server due to default <code>/etc/resolv.conf</code> of the pod</p>
<p>Hence the dnspolicy that is desired to be applied to the deployment/pod is:</p>
<pre><code>      dnsConfig:
        nameservers:
          - &lt;ip-of-the-node&gt;
        options:
          - name: ndots
            value: '5'
        searches:
          - monitoring.svc.cluster.local
          - svc.cluster.local
          - cluster.local
      dnsPolicy: None
</code></pre>
<p>In the above configuration the <code>nameservers</code> needs to be IP of the node where pod gets deployed. Since I have three worker nodes, I cannot hard-code the value to specific worker node's IP. I would not prefer configuring the pod to get deployed to particular node since if the resources are not sufficient for the pod to get deployed in a particular node, the pod might remain in pending state.</p>
<p>How can I make the <code>nameservers</code> to get value of the IP address of the node where pod gets deployed?</p>
<p>Or is it possible to update the <code>nameservers</code> with some kind a of a generic argument so that the pod will be able to connect to smtp server.</p>

<p><code>dnsConfig</code> <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-dns-config" rel="nofollow noreferrer">support up to 3 IP addresses</a> specified so theoretically you could hard code it in the <code>nameservers</code> field. However as a workaround you can pass node ip address as a <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#envvarsource-v1-core" rel="nofollow noreferrer">env variable and then pass it to the pod</a>. Example:</p>
<pre><code>spec:
  containers:
  - name: envar-demo-container
    command: [&quot;/bin/sh&quot;]
    args: [&quot;-c&quot;, &quot;printenv NODE_IP &gt;&gt; /etc/resolv.conf&quot;]
    image: nginx
    env:
    - name: NODE_IP
      valueFrom:
        fieldRef: 
          fieldPath: status.hostIP
</code></pre>
<p><code>fieldPath: status.hostIP</code> takes IP address of the node that pod is deployed on and saves it as a environment variable. Then it is written to <code>/etc/resolv.conf</code>.</p>
