Learn Labs
Availability

Scheduling & Disruptions

Topology spread, taints, drains, and PodDisruptionBudgets

Three replicas protect nothing if they're on the same node. The scheduler places each pod using filters (which nodes can run it: resources, taints, affinity, volume topology) and scores (which of those is best). This lesson is about telling it what "best" means for availability.

Spreading across zones

topologySpreadConstraints:- maxSkew: 1zones may differ by at most 1 podtopologyKey: topology.kubernetes.io/zonethe node label that defines a "domain"whenUnsatisfiable: DoNotSchedulehard rule (ScheduleAnyway = preference)nodeTaintsPolicy: Honorignore tainted (e.g. cordoned) nodeslabelSelector: { matchLabels: { app: web } }matchLabelKeys: ["pod-template-hash"]count only pods of the same revision
momentzone-alab-workerzone-blab-worker2zone-clab-worker3ScheduleAnyway, after HPA scale-down✓!✗DoNotSchedule + Honor, start✓✓✓after draining zone-a and zone-b✗✗!uncordoned, 20 s later✗✗!after rollout restart✓✓✓

The first version used whenUnsatisfiable: ScheduleAnyway, and the lab found zone-c with no web pods and zone-b with two:

1. web pods by node: {'lab-worker (zone-a)': ['5z65x'], 'lab-worker2 (zone-b)': ['mfktj', 'pxkwv']}

ScheduleAnyway is only a scoring preference, and scale-down ignores spreading entirely: when the HPA went from 9 to 3, the ReplicaSet chose which pods to delete without looking at zones. With DoNotSchedule the start of the next run was one pod per zone.

nodeTaintsPolicy: Honor matters during drains: a cordoned node carries a NoSchedule taint. With the default (Ignore), its zone still counts as a domain with zero pods, and a hard spread constraint can refuse to place pods anywhere else.

Taints and tolerations

A taint on a node repels pods that don't tolerate it. The control plane node is tainted (node-role.kubernetes.io/control-plane:NoSchedule), which is why no app pod ever lands there. kubectl cordon adds node.kubernetes.io/unschedulable; a dead node gets node.kubernetes.io/unreachable (see Node Failure).

Drains and PodDisruptionBudgets

A drain cordons a node, then evicts its pods through the eviction API, which checks PodDisruptionBudgets first:

apiVersion: policy/v1kind: PodDisruptionBudgetspec:minAvailable: 2voluntary disruptions may never leave fewer than 2 ready web podsselector: { matchLabels: { app: web } }

scheduling.py drains two nodes at the same time, under traffic:

./scripts/lab.sh scheduling.py
1. web pods by node: {'lab-worker (zone-a)': ['2g8t5'], 'lab-worker2 (zone-b)': ['mkg8b'], 'lab-worker3 (zone-c)': ['hcmw2']}
 drain lab-worker: ok
 drain lab-worker2: ok

2. both drains finished in 17s; evictions refused by the PDB along the way: 2
 e.g. error when evicting pods/"web-65bf54497c-2g8t5" -n "shop" (will retry after 5s):
      Cannot evict pod as it would violate the pod's disruption budget.
 traffic during the drains: 348 requests, 348 ok, errors: none
 web pods by node now: {'lab-worker3 (zone-c)': ['746ch', 'g9z5n', 'hcmw2']}
drain lab-workerdrain lab-worker2API (eviction)PDB minAvailable 2evict web-…2g8t53 ready, may lose 1evict web-…mkg8b429: would violate the budgetretry after 5 sreplacement ready: 3 againevict again: allowed

The PDB allowed one eviction, refused the second until the replacement was ready, then allowed it: never fewer than 2 ready pods, zero client errors. Cluster upgrades drain every node in turn; PDBs are what make that safe.

Pods don't move back

3. uncordoned, 20 s later: {'lab-worker3 (zone-c)': ['746ch', 'g9z5n', 'hcmw2']}
 after a rollout restart: {'lab-worker (zone-a)': ['b5btr'], 'lab-worker2 (zone-b)': ['zrw26'], 'lab-worker3 (zone-c)': ['8rf6l']}

After the drain, all three pods were in one zone, and uncordoning changed nothing: the scheduler only places new pods. Losing zone-c now would take the whole app down. A rollout restart re-spread them; the descheduler project automates this.

Lab

  1. Run scheduling.py. Then set minAvailable: 3 and drain one node. What does the drain do?
  2. Change the spread constraint back to ScheduleAnyway, scale to 9 and back to 3 a few times, and record the placement.
  3. Add node-role.kubernetes.io/control-plane as a toleration to web. Where can it schedule now? Why is that a bad idea?

On this page