Topology Spread Constraints for High Availability
Spread replicas evenly across zones or nodes to survive topology failures.
In plain words
Topology spread is placing board-game pieces across tables so one blocked table cannot remove most of the game. The simple Kubernetes rule is: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
Think of it like…
Topology spread is placing board-game pieces across tables so one blocked table cannot remove most of the game.
Where you’ve seen it
A cluster operator validates a small change and runs kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zone. Expected evidence: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement. If the run instead shows this symptom, stop and restore the last known state: Hard ScheduleAnyway is a preference, while DoNotSchedule can strand replicas when eligible nodes or labeled zones are unavailable.
Words you’ll hear
- Topology Spread
- For this lesson, Topology Spread is the controlling idea: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
- HA
- HA is the checkpoint; run
kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zoneand inspect the owner chain. Hard ScheduleAnyway is a preference, while DoNotSchedule can strand replicas when eligible nodes or labeled zones are unavailable. - Zones
- Zones is the outcome to preserve; the cost is explicit: Explicit skew guards against correlated zone loss, but strict spreading can reduce schedulability during partial capacity and must align with actual topology labels.
- Verification evidence
- The evidence command is
kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zone. It connects the declaration to this behavior: Spread replicas evenly across zones or nodes to survive topology failures.
Visual diagram
Theory & deep dive
How Topology Spread reaches the intended state
Spread replicas evenly across zones or nodes to survive topology failures. Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
The concrete checkpoint is kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zone; compare the Topology Spread owner, HA state, and Zones outcome instead of treating YAML acceptance as proof.
Run kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zone after the change and correlate the result with Events and the owning object. Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
HA: failure boundary and production cost
Hard ScheduleAnyway is a preference, while DoNotSchedule can strand replicas when eligible nodes or labeled zones are unavailable. The prerequisite contract is concrete: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
Explicit skew guards against correlated zone loss, but strict spreading can reduce schedulability during partial capacity and must align with actual topology labels. A safe design limits blast radius, records the last good configuration, and uses kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zone as a deterministic rollback checkpoint.
Capture the current state with kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zone, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: Hard ScheduleAnyway is a preference, while DoNotSchedule can strand replicas when eligible nodes or labeled zones are unavailable.
How it works, step by step
Step 1 of 41. Model the cluster contract
Start from a minimal API, context, or node condition and make this contract explicit: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
- Goal
- Spread replicas evenly across zones or nodes to survive topology failures.
- Owner
- Topology Spread
When to use it & trade-offs
What it is
Spread replicas evenly across zones or nodes to survive topology failures. Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
Why it matters: Hard ScheduleAnyway is a preference, while DoNotSchedule can strand replicas when eligible nodes or labeled zones are unavailable. The invariant at risk is specific: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement. The quickest fact check before changing the design is kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zone.
When to reach for it
- Use Topology Spread to enforce this invariant: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
- Use HA evidence from
kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zonein reviews and incident timelines. Spread replicas evenly across zones or nodes to survive topology failures. - Choose the platform-level abstraction route only when this cost is justified by governance or scale: Explicit skew guards against correlated zone loss, but strict spreading can reduce schedulability during partial capacity and must align with actual topology labels.
When to avoid or be careful
- Avoid assuming Topology Spread is complete after YAML submission; the required behavior is concrete: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
- Avoid treating the next symptom as random; check the owner and state with
kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zonefirst: Hard ScheduleAnyway is a preference, while DoNotSchedule can strand replicas when eligible nodes or labeled zones are unavailable. - Avoid adopting a heavier platform wrapper before measuring its cost: Explicit skew guards against correlated zone loss, but strict spreading can reduce schedulability during partial capacity and must align with actual topology labels.
Native, manual, and managed paths for Topology Spread
kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zone.Strengths: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
Watch out: Explicit skew guards against correlated zone loss, but strict spreading can reduce schedulability during partial capacity and must align with actual topology labels. Recovery must also recognize this signal: Hard ScheduleAnyway is a preference, while DoNotSchedule can strand replicas when eligible nodes or labeled zones are unavailable.
kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zone; the expected invariant is: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.Strengths: kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zone gives immediate feedback without first building a platform layer.
Watch out: A manual change can hide drift, and unlike Topology Spread, it does not make this symptom self-documenting: Hard ScheduleAnyway is a preference, while DoNotSchedule can strand replicas when eligible nodes or labeled zones are unavailable.
kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zone.Strengths: Platform controls can wrap this exact behavior in policy or dashboards: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
Watch out: The added platform ownership buys value at this cost: Explicit skew guards against correlated zone loss, but strict spreading can reduce schedulability during partial capacity and must align with actual topology labels.
Interview signals & numbers to know
When this topic comes up
- Interview anchor: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
- Trace Topology Spread to Zones through HA; the invariant is: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
- Recognize the symptom: Hard ScheduleAnyway is a preference, while DoNotSchedule can strand replicas when eligible nodes or labeled zones are unavailable.
- Justify the cost: Explicit skew guards against correlated zone loss, but strict spreading can reduce schedulability during partial capacity and must align with actual topology labels.
- Verify with kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zone instead of only inspecting YAML.
Benchmarks & rules of thumb
- 1
- maxSkew means replicas differ by no more than one in a simple equal-weight spread
- 2
- whenUnsatisfiable actions are DoNotSchedule and ScheduleAnyway
- 3
- common topology levels are zone, node, and hostname
Common mistakes & follow-ups
Common interview mistakes
- Debugging only the child object misses the Topology Spread owner contract: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement.
- Ignoring this telltale condition leads to unrelated changes: Hard ScheduleAnyway is a preference, while DoNotSchedule can strand replicas when eligible nodes or labeled zones are unavailable.
- Repeating
kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zonewithout an owner for remediation wastes retry cost. Explicit skew guards against correlated zone loss, but strict spreading can reduce schedulability during partial capacity and must align with actual topology labels.
Likely interviewer follow-ups
- How would API output and runtime evidence prove this behavior: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement?
- Which owner object, logs, and Events would you inspect for this symptom-Hard ScheduleAnyway is a preference, while DoNotSchedule can strand replicas when eligible nodes or labeled zones are unavailable-?
- At what threshold would this cost become unacceptable: Explicit skew guards against correlated zone loss, but strict spreading can reduce schedulability during partial capacity and must align with actual topology labels?
kubectl get pod -l app=api -o wide; kubectl get nodes -L topology.kubernetes.io/zone, name the failure, then justify the cost. Invariant: Topology spread constraints compare replica counts across domains such as zones and use maxSkew plus whenUnsatisfiable to shape placement. Failure: Hard ScheduleAnyway is a preference, while DoNotSchedule can strand replicas when eligible nodes or labeled zones are unavailable. Cost: Explicit skew guards against correlated zone loss, but strict spreading can reduce schedulability during partial capacity and must align with actual topology labels.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Topology Spread Constraints for High Availability with generative AI interview Q&A and hands-on practice.