Required Node Affinity Rules
What you'll learn: How to use requiredDuringSchedulingIgnoredDuringExecution to enforce mandatory node selection constraints in Kubernetes.
The Hard Rule for Pod Placement
While node selectors provide simple node selection, required node affinity gives you powerful, mandatory rules that a Pod must satisfy to be scheduled. Think of it like a strict entrance requirement—if a node doesn't meet the criteria, the Pod simply won't be placed there.
The requiredDuringSchedulingIgnoredDuringExecution field creates hard constraints. The long name tells you exactly what it does:
- requiredDuringScheduling: The rule MUST be met when scheduling the Pod
- IgnoredDuringExecution: If node labels change after the Pod is running, it stays put
How It Works
Required affinity uses nodeSelectorTerms with label matching expressions. You can match labels using operators like In, NotIn, Exists, DoesNotExist, Gt, and Lt.
apiVersion: v1
kind: Pod
metadata:
name: cpu-intensive-app
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: cpu-type
operator: In
values:
- high-performance
- extreme
This Pod will only schedule on nodes labeled with cpu-type=high-performance or cpu-type=extreme. If no matching nodes exist, the Pod stays in Pending state.
When to Use Required Affinity
Use required affinity when:
- Workloads need specific hardware (GPUs, SSD storage)
- Compliance requires certain node types
- Applications must avoid particular zones or regions
Key Takeaway: Required node affinity with requiredDuringSchedulingIgnoredDuringExecution creates mandatory scheduling constraints—Pods only land on nodes matching your label expressions, providing precise control over placement decisions.