How to Use the Kubernetes NMState Operator to Change the DNS Server IP and Add Options in /etc/resolv.conf on CoreOS Nodes

Solution Verified - Updated

Environment

  • Red Hat OpenShift Container Platform 4.x
  • Kubernetes NMState Operator

Issue

  • Need to change CoreOS Node DNS server IP
  • Need to add options in /etc/resolv.conf

Resolution

[core@worker-2 ~]$ cat /etc/resolv.conf 
# Generated by NetworkManager
search ocp4.example.com
nameserver 192.168.1.249
  • The Operator CR example shown below will change the DNS server IP, search domains, and options on the node worker-2.ocp4.example.com.
$ cat dns-worker2.yaml
apiVersion: nmstate.io/v1
kind: NodeNetworkConfigurationPolicy
metadata:
  name: dns-worker
spec:
  nodeSelector:
    kubernetes.io/hostname: worker-2.ocp4.example.com 
  desiredState:
    dns-resolver:
      config:
        server:
          - 192.168.1.249
          - 192.168.1.1
        search:
          - ocp4.example.com
          - mydomain.com
        options:
          - "rotate"
          - "attempts:3"
          - "timeout:2"
  • Then run oc create -f dns-worker2.yaml and check the results on the nodes
[core@worker-2 ~]$ cat /etc/resolv.conf 
# Generated by NetworkManager
search ocp4.example.com mydomain.com
nameserver 192.168.1.249
nameserver 192.168.1.1
options rotate attempts:3 timeout:2
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.