Skip to content

Latest commit

 

History

History
111 lines (80 loc) · 2.15 KB

File metadata and controls

111 lines (80 loc) · 2.15 KB

Practice Test - Node Affinity

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