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
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:
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']}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.
A PDB that can never be satisfied blocks drains forever: minAvailable: 3
with 3 replicas, or maxUnavailable: 0. Cluster upgrades then stall
waiting on your namespace. Leave room for at least one disruption.
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
- Run
scheduling.py. Then setminAvailable: 3and drain one node. What does the drain do? - Change the spread constraint back to
ScheduleAnyway, scale to 9 and back to 3 a few times, and record the placement. - Add
node-role.kubernetes.io/control-planeas a toleration to web. Where can it schedule now? Why is that a bad idea?