Preferred Node Affinity Rules
What you'll learn: How to express soft preferences for node scheduling using preferredDuringSchedulingIgnoredDuringExecution with weighted priorities.
Core Idea
Unlike required node affinity (the "must have" rules you just learned), preferred node affinity lets you give Kubernetes suggestions about where you'd like Pods to run. The scheduler tries to honor these preferences but won't reject a Pod if no matching node is available—it'll place the Pod on the best available node instead.
Think of it like hotel room requests: a required rule is "I absolutely need a non-smoking room" (if unavailable, you won't book). A preferred rule is "I'd prefer a room with an ocean view" (nice to have, but you'll take a city view if needed).
Weighting Your Preferences
The key feature here is weight (1-100). Higher weights mean stronger preferences. If multiple preferences exist, Kubernetes scores each node and picks the highest-scoring available node.
Syntax
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 80
preference:
matchExpressions:
- key: disk-type
operator: In
values:
- ssd
- weight: 20
preference:
matchExpressions:
- key: region
operator: In
values:
- us-west
Here, the scheduler strongly prefers SSD nodes (weight 80) over specific regions (weight 20), but will schedule the Pod even if neither condition is met.
When to Use
Use preferred affinity when:
- You want performance optimizations but need flexibility
- Workloads can tolerate suboptimal placement
- You're balancing multiple competing preferences
Key Takeaway: preferredDuringSchedulingIgnoredDuringExecution creates flexible, weighted scheduling hints that guide—but don't constrain—Pod placement, making your cluster more resilient while still optimizing for ideal conditions.