Node Affinity

Describe about Node Affinity

This property performs similar functions to the Node Selector, but it possesses the capability to execute more intricate operations compared to the Node Selector.

In continuation with the Node Selector exercise previously. we can use this Pod template .

# Pod Template
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels: 
    name: nginx
spec: 
  containers:
  - name: nginx
    image: nginx 
    ports:
      - containerPort: 8080
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution: (1)
        nodeSelectorTerms:
        - matchExpressions:
          - key: size        
            operator: In (2)
            values:
            - Large
            - Medium
          

(1) is property about when pod avaiable. There are 3 type.

  1. requiredDuringSchedulingIgnoredDuringExecution

  2. preferredDuringSchedulingIgnoredDuringExecution

  3. requiredDuringSchedulingRequiredDuringExecution

During Scheduling = It mean Pod does not exist in Node or first time create Pod

During Execution = It mean After Pod created (maybe someone remove label from Node)

required = Need to have if not It will not do anything. ex: requiredDuringScheduling if Node does not match the condition Pod will not be created

preferred= Have or not have it ok . ex: preferredDuringScheduling If the Node meets the specified conditions, the Pod will be created on that Node; otherwise, it will select an alternative Node.

Ignored=It will not do anything. ex: IgnoredDuringExecutionIf a Pod has already been created on the Node, subsequently removing the label from the Node will not impact the Pod. but If it's be RequiredDuringExecutionIt will terminate the Pod

Last updated