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?
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.
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