Skip to content

Node Affinity & Anti-Affinity

Node Affinity allows you to constrain which nodes your Pod is eligible to be scheduled on based on node labels:

  • requiredDuringSchedulingIgnoredDuringExecution (Hard rule): The scheduler will NOT schedule the pod unless the rule is met.
  • preferredDuringSchedulingIgnoredDuringExecution (Soft rule): The scheduler tries to find a matching node, but will schedule the pod elsewhere if no match exists.
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: topology.kubernetes.io/zone
operator: In
values: [us-east-1a, us-east-1b]