Goglides Dev 🌱

Balkrishna Pandey
Balkrishna Pandey

Posted on

Change DNS Server in Running OpenShift Cluster using NMState Operator

This blog will walk you through configuring BIND as a DNS server, manually verifying the setup, and using the nmstate operator to apply DNS configurations in a running OpenShift cluster.

Section 1: Configure BIND

  • Install BIND Packages
yum install bind bind-utils
Enter fullscreen mode Exit fullscreen mode
  • Edit BIND Configuration Modify /etc/named.conf to specify listening IP addresses and allow queries:
listen-on port 53 { 127.0.0.1; 192.168.0.1; };
allow-query { localhost; 192.168.0.0/16; };
allow-recursion { localhost; 192.168.0.0/16; };
Enter fullscreen mode Exit fullscreen mode
  • Configure Forwarders (Optional) If needed, add forwarders to delegate DNS queries:
forwarders { 8.8.8.8; 8.8.4.4; };
forward only;
Enter fullscreen mode Exit fullscreen mode
  • Verify Configuration
named-checkconf
Enter fullscreen mode Exit fullscreen mode
  • Start BIND and Enable DNS Traffic
firewall-cmd --permanent --add-service=dns
firewall-cmd --reload
systemctl enable --now named
Enter fullscreen mode Exit fullscreen mode

Section 2: Manual Verification

  • Set DNS Temporarily on OpenShift Nodes To preserve changes in /etc/resolv.conf for testing, use:
chattr +i /etc/resolv.conf
Enter fullscreen mode Exit fullscreen mode

Verify the effect of chattr:

lsattr /etc/resolv.conf
Enter fullscreen mode Exit fullscreen mode

Once DNS functionality is confirmed, revert:

chattr -i /etc/resolv.conf
Enter fullscreen mode Exit fullscreen mode
  • Test DNS Resolution
dig @localhost www.example.org
Enter fullscreen mode Exit fullscreen mode

Section 3: Using nmstate Operator to Configure in a Running Cluster

  • Install nmstate Operator
    Apply the nmstate configuration to specify the DNS server in OpenShift.

  • Apply DNS Configuration
    Use the following configuration for the DNS resolver:

apiVersion: nmstate.io/v1
kind: NodeNetworkConfigurationPolicy
metadata:
  name: worker1-dns
spec:
  nodeSelector:
    kubernetes.io/hostname: worker1
  desiredState:
    dns-resolver:
      config:
        search:
        - example.com
        server:
        - 192.168.0.10
Enter fullscreen mode Exit fullscreen mode
  • Validate
oc get nncp
Enter fullscreen mode Exit fullscreen mode

Top comments (0)