Interview's MateKubernetes
Interview's Mate

Kubernetes

K8s · Workloads · GitOps · Cloud

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Kubernetes topics
Lesson 19/ 160
01. Kubernetes Fundamentals & Architecture

Topology Spread Constraints for High Availability

Spread replicas evenly across zones or nodes to survive topology failures.

AdvancedTopology Spread · HA · Zones3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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/zone and 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

Loading interactive 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.

Verify HA, not only object creation

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.

Key takeaway: Topology Spread is implemented only when this invariant remains observable: 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.

Recover from HA drift

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.

Key takeaway: Accept the trade-off consciously: Explicit skew guards against correlated zone loss, but strict spreading can reduce schedulability during partial capacity and must align with actual topology labels.

How it works, step by step

Step 1 of 4
Operator intent

1. 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.

Topology Spread contract → owned state
Key numbers at this step
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/zone in 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/zone first: 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

Native cluster primitive
Best for: Spread replicas evenly across zones or nodes to survive topology failures. A concrete incident check is 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.

One-off administrative action
Best for: Quickly testing the HA assumption with 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.

Platform-level abstraction
Best for: Teams that need Zones integrated with guardrails; the evidence path is 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/zone without 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?
Interview tip: Interview sequence: state the invariant, run 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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Node Affinity, Pod Affinity & Pod Anti-Affinity
Next topic
Static Pods & Manual Scheduling Mechanics