Node Affinity

  node affinity -

             1.create a cluster

             2.Your Kubernetes server must be at or later than version v1.10. To check the version, enter kubectl version.

            3.add label to a node

           4. create a pod required node affinity/pref. node affinity   

            5.see o/p

follow following commands one by one to sticking-

  1.add label to a node or labels to nodes, 

This means that the pod will get scheduled only on a node that has a specific label in requiredDuringSchedulingIgnoredDuringExecution: condition.

in preferredDuringSchedulingIgnoredDuringExecution: condition, the pod will prefer a node that has a disk type=SSD label.

 

kubectl get nodes --show-labels

kubectl label nodes <your-node-name> disktype=ssd

kubectl get nodes --show-labels

create a pod required node affinity/pref. node affinity

1.for required condition, mention below condition and then apply by kubectl apply -f <filename > and o/p by using kubectl get pods --output=wide

 affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: disktype
            operator: In
            values:
            - ssd      

2.for preferred condition, mention below condition and then apply by kubectl apply -f <filename > and o/p by using kubectl get pods --output=wide

for example.


spec: affinity: nodeAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 1 preference: matchExpressions: - key: disktype operator: In values: - ssd

























explanation and demo

schedule a pod having condition is required, in which case ordered that if and only if stick the pod when node having disc type ssd. but no one node eligible for this condition so status get pending!




schedule a pod having condition is preferred, in which case request is that if stick the pod when node having disc type ssd. so, one node01 eligible for this condition so status is shown!




Comments

Popular Posts