Required affinity is a filter; preferred affinity is a score.
Use it when a Pod needs, or would like, nodes with certain labels: SSD disks, a zone, an instance family, a GPU type.
nodeAffinity
affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: # HARD nodeSelectorTerms: - matchExpressions: - {key: disktype, operator: In, values: [ssd]} preferredDuringSchedulingIgnoredDuringExecution: # SOFT - weight: 80 preference: matchExpressions: - {key: topology.kubernetes.io/zone, operator: In, values: [europe-west1-b]}
required...
Acts like a filter. No matching node means the Pod stays Pending.
preferred...
Acts like a score (weight 1 to 100). The Pod still schedules elsewhere if needed.
...IgnoredDuringExecution
Checked only at scheduling time. Changing a node label later does not evict a running Pod.
Operators
In, NotIn, Exists, DoesNotExist, Gt, Lt. Use Exists when only the label's presence matters.