Video in progress
What do you configure so your service does not go down during a node drain or a cluster upgrade?
A PodDisruptionBudget limits how many pods can go down at once; anti-affinity and topology spread distribute replicas across different nodes and zones. Without them, all three replicas may sit on one node and a drain takes them down at once.
📖 Answer
Many teams set replicas: 3 and consider themselves safe. But the scheduler may place all three pods on one node. A node upgrade, and the service is completely gone.
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: orders
spec:
maxUnavailable: 1
selector:
matchLabels: { app: orders }
---
# inside the Deployment pod spec
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels: { app: orders }
Interviewers often see people slip here: a PDB limits only voluntary disruptions (drain, the eviction API). If a node suddenly dies, it does not help, and spreading is what works there.
Traps:
minAvailable: 3withreplicas: 3: a drain never finishes, and the platform team will be unhappy with you.maxUnavailable: 1is safer;whenUnsatisfiable: DoNotScheduleleaves pods in Pending if there are few zones;- for a PDB to work, graceful shutdown also has to be right, otherwise even when pods go down one by one, each one cuts off requests;
- for an evicted pod to be rescheduled, the cluster needs free room. If all nodes are 95% full, the PDB just stalls the drain.
How to test: run kubectl drain in staging while a load test is running. The error count should be zero.
Sign up to mark studied questions and save your progress.