How to set node ip as nameserver in dnsConfig? How to set node ip as nameserver in dnsConfig? kubernetes kubernetes

How to set node ip as nameserver in dnsConfig?


dnsConfig support up to 3 IP addresses specified so theoretically you could hard code it in the nameservers field. However as a workaround you can pass node ip address as a env variable and then pass it to the pod. Example:

spec:  containers:  - name: envar-demo-container    command: ["/bin/sh"]    args: ["-c", "printenv NODE_IP >> /etc/resolv.conf"]    image: nginx    env:    - name: NODE_IP      valueFrom:        fieldRef:           fieldPath: status.hostIP

fieldPath: status.hostIP takes IP address of the node that pod is deployed on and saves it as a environment variable. Then it is written to /etc/resolv.conf.