Kubernetes pod distribution amongst nodes with preferred mode
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In Kubernetes, preferred scheduling rules influence placement without making it mandatory. That matters when you want pods spread across nodes for resilience, but you still want the scheduler to place the pod somewhere even if the ideal layout is temporarily impossible.
Preferred Versus Required Rules
Kubernetes offers both hard and soft scheduling constraints. Hard constraints must be satisfied or the pod stays pending. Preferred constraints are scoring hints: the scheduler tries to honor them, but it can ignore them if necessary.
For node affinity and pod anti-affinity, the preferred form is named preferredDuringSchedulingIgnoredDuringExecution. The long name is worth remembering because it explains the behavior exactly.
Preferred Pod Anti-Affinity Example
If you want replicas of the same app to avoid landing on the same node when possible, preferred pod anti-affinity is a common tool.
This tells the scheduler to prefer nodes that do not already run another pod with label app=web on the same hostname. It improves distribution, but it does not guarantee perfect balancing.
What "Preferred" Really Means in Practice
The scheduler turns preferred rules into scores. Higher weights increase the rule's influence, but scoring is still part of a larger decision process that includes resource availability and other scheduling plugins.
That means if the cluster has only one eligible node with enough CPU and memory, Kubernetes will place the pod there even when the anti-affinity preference is violated. That is the entire point of preferred mode: better placement when possible, successful placement when necessary.
Node Affinity Can Also Be Preferred
You can apply the same idea to node labels. For example, maybe you would like pods to land on SSD-backed nodes but still allow them to run elsewhere.
This is useful for cost or performance preferences that should not block scheduling completely.
Use Topology Spread Constraints for Better Evenness
If your real goal is balanced replica distribution, topologySpreadConstraints often expresses that intent more directly than anti-affinity.
ScheduleAnyway behaves like a soft rule. Kubernetes tries to keep the skew low across nodes but still schedules when a perfect spread cannot be achieved.
For many modern workloads, topology spread constraints are easier to reason about than anti-affinity because they describe the distribution goal directly.
Choosing the Right Tool
Use preferred pod anti-affinity when you want replicas separated from each other and the rule is fundamentally about not colocating similar pods. Use preferred node affinity when you prefer certain nodes based on labels. Use topology spread constraints when you care most about even placement across a domain such as nodes or zones.
These tools can be combined, but too many soft preferences can make scheduling behavior harder to predict.
Common Pitfalls
A common mistake is expecting preferred rules to guarantee one pod per node. They do not. If you need a hard guarantee, use required constraints and accept that pods may remain pending.
Another issue is using a weak weight and assuming the preference will dominate scheduling. Preferred rules compete with other scoring inputs.
Finally, remember that IgnoredDuringExecution means running pods are not evicted later just because a better node becomes available.
Summary
- Preferred scheduling rules are soft hints, not guarantees.
- '
preferredDuringSchedulingIgnoredDuringExecutionimproves placement without blocking scheduling.' - Pod anti-affinity helps separate similar pods across nodes.
- Topology spread constraints are often the clearest way to express even distribution.
- Soft rules are best when availability matters more than perfect placement.
Related reading
- Kubernetes pod events showing as none
- Kubernetes Pod fails with CrashLoopBackOff
- Kubernetes pod gets recreated when deleted
- Kubernetes pod not READY
- Kubernetes pod pending when a new volume is attached EKS
- Kubernetes Pod reporting more memory usage than actual process consumption
- Kubernetes pod resolve external kafka hostname in coredns not as hostaliases inside pod
- Kubernetes Pod Warning 1 nodes had volume node affinity conflict

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.