Skip to content

Latest commit

 

History

History
111 lines (95 loc) · 3.04 KB

handson__ocp4_nmstate_operator.md

File metadata and controls

111 lines (95 loc) · 3.04 KB

Test to change DNS server using NMState Operator

This operator is Tech preview as of OCPv4.7. https://github.com/nmstate/kubernetes-nmstate

Install Kubernetes NMState Operator

Create openshift-nmstate namespace as follows before installation.

$ oc create namespace openshift-nmstate

Install the operator along to the official docs: https://docs.openshift.com/container-platform/4.7/networking/k8s_nmstate/k8s-nmstate-about-the-k8s-nmstate-operator.html

Create NMState instance

To deploy required pods, create NMState CR first.

$ oc create -f - <<EOF
apiVersion: nmstate.io/v1beta1
kind: NMState
metadata:
  name: nmstate
spec:
  nodeSelector:
    beta.kubernetes.io/arch: amd64
EOF

$ oc get pod -n openshift-nmstate
NAME                                READY   STATUS    RESTARTS   AGE
nmstate-handler-5f5fd               1/1     Running   0          35s
nmstate-handler-6j56q               1/1     Running   0          35s
nmstate-handler-r8vwl               1/1     Running   0          35s
nmstate-handler-rqcm7               1/1     Running   0          35s
nmstate-handler-twfnf               1/1     Running   0          35s
nmstate-handler-xrp47               1/1     Running   0          35s
nmstate-operator-6cbb6848dc-rbtj5   1/1     Running   0          7m44s
nmstate-webhook-6c4bd947b-89dcn     0/1     Running   0          35s
nmstate-webhook-6c4bd947b-mgjhr     1/1     Running   0          35s

Test

Add DNS server to a specific worker node using "kubernetes.io/hostname" label. The configuration is straightforward and simple.

# oc create -f - <<EOF
apiVersion: nmstate.io/v1beta1
kind: NodeNetworkConfigurationPolicy
metadata:
  name: dns-for-specific-node
spec:
  nodeSelector:
    kubernetes.io/hostname: "ip-10-0-246-84"
  desiredState:
    interfaces:
    - name: ens5
      type: ethernet
      state: up
      ipv4:
        dhcp: true
        auto-dns: false
        enabled: true
    dns-resolver:
      config:
        server:
        - 10.0.0.2
        - 8.8.8.8
EOF

$ oc get NodeNetworkConfigurationPolicy
NAME                    STATUS
dns-for-specific-node   SuccessfullyConfigured

Wow, added 8.8.8.8 DNS server is added to the specified worker node only.

$ oc debug node/ip-10-0-138-207.ap-northeast-1.compute.internal
Starting pod/ip-10-0-138-207ap-northeast-1computeinternal-debug ...
To use host binaries, run `chroot /host`
Pod IP: 10.0.138.207
If you don't see a command prompt, try pressing enter.
sh-4.4# chroot /host
sh-4.4# cat /etc/resolv.conf 
# Generated by NetworkManager
search ap-northeast-1.compute.internal
nameserver 10.0.0.2
sh-4.4# exit
exit
sh-4.4# exit
exit

Removing debug pod ...
$ oc debug node/ip-10-0-246-84.ap-northeast-1.compute.internal
Starting pod/ip-10-0-246-84ap-northeast-1computeinternal-debug ...
To use host binaries, run `chroot /host`
chroot /host
Pod IP: 10.0.246.84
If you don't see a command prompt, try pressing enter.
sh-4.4# chroot /host
sh-4.4# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 10.0.0.2
nameserver 8.8.8.8
sh-4.4# 

Done.