Affinity Weight and Priorities
What you'll learn: How Kubernetes scheduler uses numerical weights to rank nodes and make optimal placement decisions when affinity rules conflict or overlap.
How the Scheduler Scores Nodes
When you define preferred affinity rules (both node and pod affinity), Kubernetes doesn't just pick any matching node—it scores them. Each preferred affinity term includes a weight field (1-100) that tells the scheduler how important that preference is.
Think of it like a talent show with multiple judges: each judge (affinity rule) scores contestants (nodes), and their scores are weighted by importance. A celebrity judge might have weight 80, while a guest judge has weight 20. The contestant with the highest total wins.
How Scoring Works
The scheduler evaluates each preferred affinity rule:
- If a node satisfies the rule: it receives the rule's full weight as points
- If it doesn't satisfy the rule: it receives 0 points for that rule
- All points are summed across all affinity rules for that node
- The node with the highest total score wins
For example, if you have two preferences:
- "Prefer nodes in zone us-east-1a" (weight: 80)
- "Prefer nodes with SSD storage" (weight: 50)
A node matching both gets 130 points. A node matching only the zone gets 80 points. The scheduler picks the highest scorer.
Multiple Factors
The scheduler also considers other factors beyond affinity (resource availability, taints/tolerations, etc.), but affinity weights significantly influence the final decision.
Key Takeaway: Affinity weights (1-100) let you prioritize scheduling preferences numerically—higher weights make rules more influential in the scheduler's node selection scoring algorithm.