- Take me to Practice Test
Solutions to practice test - node affinity
-
Run the command 'kubectl describe node node01' and count the number of labels under
Labels Section
.$ kubectl describe node node01
-
Run the command 'kubectl describe node node01' and see the label section
$ kubectl describe node node01
-
Run the command 'kubectl label node node01 color=blue'.
$ kubectl label node node01 color=blue
-
Run the below commands
$ kubectl create deployment blue --image=nginx $ kubectl scale deployment blue --replicas=6
-
Check if master and node01 have any taints on them that will prevent the pods to be scheduled on them. If there are no taints, the pods can be scheduled on either node.
$ kubectl describe nodes|grep -i taints $ kubectl get pods -o wide
-
Answer file at /var/answers/blue-deployment.yaml
$ kubectl edit deployment blue
Add the below under the template.spec section
affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: color operator: In values: - blue
-
Run the command 'kubectl get pods -o wide' and see the Node column
$ kubectl get pods -o wide
-
Answer file at /var/answers/red-deployment.yaml Add the below under the template.spec section
affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: node-role.kubernetes.io/master operator: Exists
$ kubectl create -f red-deployment.yaml
$ kubectl get pods -o wide