node affinity
Node affinity is a Kubernetes scheduling constraint that guides pod placement to specific nodes based on labels and rules. It allows workloads to prefer or require running on nodes with particular attributes.
Node affinity is a Kubernetes feature that controls which nodes a pod can be scheduled on by matching against node labels. Unlike nodeSelector, which uses simple equality matching, node affinity supports more complex expressions with operators like In, NotIn, Gt, and Lt.
There are two types: requiredDuringSchedulingIgnoredDuringExecution (hard constraint—the pod will not schedule if no matching node exists) and preferredDuringSchedulingIgnoredDuringExecution (soft constraint—the scheduler tries to place the pod on a matching node but will schedule elsewhere if necessary).
Example: A database pod might use node affinity to require nodes labeled storage=ssd and zone=us-east-1a. The scheduler will only place the pod on nodes matching these labels, ensuring optimal performance and data residency.