Will requiredDuringSchedulingIgnoredDuringExecution nodeAffinity persist if a pod gets evicted and rescheduled?

4/14/2020

So, let's say we assign requiredDuringSchedulingIgnoredDuringExecution type to node affinity and specify some node selector terms. Let's suppose a pod gets created according to the terms. But, what if a pod gets evicted and it is rescheduled. Would that node affinity/node selector terms which is requiredDuringSchedulingIgnoredDuringExecution be taken into account when a new pod is created?

-- Bissenbay Dauletbayev
kubernetes
openshift

2 Answers

4/15/2020

Scheduling is done by Kubernetes scheduler and every time it will schedule or reschedule a pod it will consider the affinity and antiaffiny defined in pod spec.

-- Arghya Sadhu
Source: StackOverflow

4/15/2020

requiredDuringSchedulingIgnoredDuringExecution type of nodeAffinity, unofficially calls "hard rule" guarantee you the pod will be created/RECREATED exactly based on rules you defined.

Example from official kubernetes documentation:

spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/e2e-az-name
            operator: In
            values:
            - e2e-az1
            - e2e-az2

Above spec will always recreate pod ONLY in nodes with label=kubernetes.io/e2e-az-name that contains values e2e-az1 or e2e-az2

-- VKR
Source: StackOverflow