Kubernetes / Advanced: extensibility, resilience, and lifecycle / Lesson 21
Reason about Pod topology spread constraints
Analyze eligible domains, selectors and skew when distributing Kubernetes Pods across failure domains.
On this page
Lesson goals
- Explain topology domains and matching Pod counts.
- Evaluate a simple hard spread constraint.
- Recognize availability and scheduling trade-offs.
Define the scheduling goal
Topology spread constraints guide placement of matching Pods across domains identified by node labels. Choose a topology key that represents the intended failure boundary and verify its labels on eligible nodes. A spread constraint is a scheduling rule, not a promise that a service survives every failure. The records below are synthetic and do not represent a real scheduler decision.
Evaluate a simple skew
In the first record two eligible zones have two and one matching Pods. With maxSkew 1 and DoNotSchedule, adding the next matching Pod to zone-a would make counts three and one, exceeding the permitted skew; zone-b would make two and two. This simplified example assumes both domains are eligible and all other scheduling requirements are satisfied. Actual scheduling evaluates additional constraints.
domains:
zone-a: 2
zone-b: 1
max_skew: 1
when_unsatisfiable: DoNotSchedule
The record illustrates a hard constraint; it is not a Pod manifest or cluster output.
Match the incoming workload
The selector determines which Pods count; the incoming Pod should match its own selector. The record assumes matching labels and two eligible domains. Missing topology labels, affinity, taints and resource requests can change eligibility, so inspect them before blaming spread alone.
incoming_pod_labels: app=catalog
selector: app=catalog
eligible_domains: [zone-a, zone-b]
The record identifies assumed matches and domains; it does not schedule anything.
Choose the availability trade-off
DoNotSchedule can leave a Pod pending when the hard constraint cannot be met. ScheduleAnyway instead expresses a preference, while other scheduler conditions still apply. Neither choice guarantees even distribution after scale-down or during an outage. Compare the availability cost of fewer running replicas with the risk of concentration and document the workloadโs failure objective.
Verify in a controlled lab
In an authorized lab, inspect node labels, capacity, selector and scheduler events. Compare placement with the expected calculation and test a missing-domain scenario. Preserve sanitized evidence and verify application capacity separately; placement alone does not prove recovery.
Common errors and fixes
The selector does not match the incoming Pod
- Why it happens
- The Pod may not count itself in its intended group.
- How to fix it
- Align the selector and Pod labels after reviewing the workload.
- Prevent it next time
- Test the selection with synthetic labels.
A pending Pod is blamed only on spread
- Why it happens
- Resource requests, affinity or taints may also prevent scheduling.
- How to fix it
- Read scheduler events and inspect all relevant constraints.
- Prevent it next time
- Record the eligible nodes and their capacity.
Spread is treated as a complete availability guarantee
- Why it happens
- Shared dependencies or lost capacity can still cause failure.
- How to fix it
- Test the full application failure scenario.
- Prevent it next time
- Review service capacity and recovery objectives separately.
2 practice exercises
1. Two eligible zones have counts 2 and 1 with hard maxSkew 1. Where can a matching next Pod go?
Show worked solution
Under the stated assumptions it can go to the second zone, yielding 2 and 2; placement in the first would yield 3 and 1.
2. All nodes in one zone are unavailable. Does a spread rule guarantee a new replica starts?
Show worked solution
No. Eligibility, the hard constraint and other scheduling requirements determine whether any node fits.
Key takeaways
- Spread uses matching Pods and eligible labeled domains.
- Hard balance can leave a Pod pending.
- Placement is one part of application availability.