Pod Disruption Budgets
Maintain availability during voluntary disruptions like node drains and cluster upgrades.
Time: ~10 minutes Difficulty: Intermediate
What You Will Learn
Section titled “What You Will Learn”- PodDisruptionBudgets (PDB): limit how many pods can be down simultaneously
minAvailablevsmaxUnavailableand when to use each- How PDBs interact with
kubectl drainand node maintenance - What counts as voluntary vs involuntary disruption
Deploy
Section titled “Deploy”Navigate to the demo directory:
cd demos/pod-disruption-budgetskubectl apply -f manifests/namespace.yamlkubectl apply -f manifests/app.yamlkubectl apply -f manifests/pdb-min-available.yamlCheck the PDB:
kubectl get pdb -n pdb-demoYou should see ALLOWED DISRUPTIONS: 2 (4 replicas - 2 minAvailable = 2 can be disrupted).
Test: Eviction Respects the PDB
Section titled “Test: Eviction Respects the PDB”The kubectl drain command respects PDBs. On minikube (single node), we can simulate this with the eviction API:
# Try to evict pods one at a timekubectl delete pod -l app=web-app -n pdb-demo --wait=falsekubectl get pods -n pdb-demo -wKubernetes will not evict pods below the minAvailable threshold during voluntary disruptions.
Test: Scale Down Interaction
Section titled “Test: Scale Down Interaction”# Scale to 2 replicas (matches minAvailable exactly)kubectl scale deploy web-app --replicas=2 -n pdb-demokubectl get pdb -n pdb-demoNow ALLOWED DISRUPTIONS: 0. No voluntary evictions are possible.
# Scale back upkubectl scale deploy web-app --replicas=4 -n pdb-demokubectl get pdb -n pdb-demoALLOWED DISRUPTIONS goes back to 2.
Alternative: maxUnavailable
Section titled “Alternative: maxUnavailable”Delete the first PDB and apply the alternative:
kubectl delete pdb web-app-pdb -n pdb-demokubectl apply -f manifests/pdb-max-unavailable.yamlkubectl get pdb -n pdb-demomaxUnavailable: 1 means at most 1 pod can be down. With 4 replicas, ALLOWED DISRUPTIONS: 1.
What is Happening
Section titled “What is Happening”manifests/ namespace.yaml # pdb-demo namespace app.yaml # 4-replica Deployment pdb-min-available.yaml # At least 2 pods must be running pdb-max-unavailable.yaml # At most 1 pod can be unavailableVoluntary vs involuntary disruptions:
| Voluntary (PDB applies) | Involuntary (PDB ignored) |
|---|---|
kubectl drain | Node crash |
| Cluster autoscaler scale-down | OOM kill |
| Rolling updates | Hardware failure |
| Manual eviction API | Kernel panic |
Choosing minAvailable vs maxUnavailable:
| Use | When |
|---|---|
minAvailable: 2 | You need at least N pods for quorum or redundancy |
maxUnavailable: 1 | You want to limit blast radius during maintenance |
maxUnavailable: 25% | Percentage-based for larger deployments |
Cleanup
Section titled “Cleanup”kubectl delete namespace pdb-demoFurther Reading
Section titled “Further Reading”See docs/deep-dive.md for a detailed explanation of the eviction API, PDB interaction with rolling updates, unhealthy pod eviction policies, and PDB strategies for StatefulSets.
Next Step
Section titled “Next Step”Move on to Prometheus & Grafana to learn cluster monitoring and observability.