Overview and What You Will Learn
A Pod Disruption Budget (PDB) tells Kubernetes the minimum number of pods that must stay available, or the maximum that may be down, while it deliberately evicts pods for maintenance. It protects a service during node drains, cluster upgrades and autoscaler scale-downs, where without a PDB all of a service's pods can be evicted at nearly the same time. In this lab you will use a throwaway multi-node cluster to see a PDB block a drain, fix the budget, and let the drain complete.
- Choosing between
minAvailableandmaxUnavailable - Seeing exactly what a PDB does and does not protect
- Reading
ALLOWED DISRUPTIONSand the PDB status fields - Diagnosing a node drain that hangs
- Protecting quorum-based StatefulSets
- Combining a PDB with replicas, readiness probes and spread constraints
Why This Matters in Production
A PDB decides whether a routine upgrade is invisible or an outage. Imagine a payments API with three pods during a cluster upgrade that drains nodes one after another. A drain evicts pods immediately and does not wait for replacements to become Ready, so a quick sequence of drains can leave one pod, or none, serving production traffic. Cloud-managed upgrades on EKS, GKE and AKS respect PDBs, so a correct budget is often the only thing between an upgrade and a user-facing incident.
Core Principles
A PDB applies only to voluntary evictions made through the Eviction API, such as kubectl drain, node upgrades, and cluster autoscaler or Karpenter scale-downs. When an eviction would take the matching pods below the budget, the API refuses it, and the drain retries until a replacement pod is Ready elsewhere and the budget allows the eviction.
Be precise about what a PDB does not cover:
| Event | Does a PDB apply? |
|---|---|
kubectl drain, node upgrades, autoscaler scale-down |
Yes, they use the Eviction API |
| Deployment rolling updates | No, controlled by maxUnavailable and maxSurge in the strategy |
kubectl delete pod |
No, direct deletion bypasses the budget |
| Node crash, kernel panic, OOM kill | No, these are involuntary |
You set exactly one of two fields. minAvailable is the number or percentage of pods that must stay available, and maxUnavailable is the number or percentage that may be down. Percentages are rounded up, so maxUnavailable: "10%" with 5 pods allows 1 disruption, and minAvailable: "60%" with 3 pods requires 2.
| Setting | Best for | Watch out |
|---|---|---|
minAvailable: N |
A known floor, such as a quorum of 2 | If replicas fall to N or below, drains block until you fix it |
maxUnavailable: N |
Services that scale up and down | Less obvious to read during an incident |
| A percentage | Autoscaled workloads | Round-up behaviour can surprise you on small replica counts |
SecurityTreat an unsatisfiable budget as an operational hazard. A PDB with
minAvailableequal to the replica count, or a single replica withminAvailable: 1, makes drains wait forever, so upgrades stall until someone removes it.
Detailed Step-by-Step Practical Lab
Step 1 - Create a Throwaway Multi-Node Cluster
Drains need more than one node, so use kind with one control plane and three workers:
kind: ClusterapiVersion: kind.x-k8s.io/v1alpha4nodes: - role: control-plane - role: worker - role: worker - role: workerkind create cluster --name pdb-lab --config kind-pdb-lab.yamlkubectl get nodesStep 2 - Deploy a Service with Three Replicas
The readiness probe matters because a PDB counts only Ready pods. The spread constraint puts one pod on each node, so a single node drain affects one pod:
# payments-api.yamlapiVersion: apps/v1kind: Deploymentmetadata: name: payments-apispec: replicas: 3 selector: matchLabels: app: payments-api strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 maxSurge: 1 template: metadata: labels: app: payments-api spec: topologySpreadConstraints: - maxSkew: 1 topologyKey: kubernetes.io/hostname whenUnsatisfiable: ScheduleAnyway labelSelector: matchLabels: app: payments-api containers: - name: api image: nginx:1.27 ports: - containerPort: 80 readinessProbe: httpGet: path: / port: 80 periodSeconds: 5kubectl apply -f payments-api.yamlkubectl rollout status deployment/payments-apikubectl get pods -l app=payments-api -o wideStep 3 - Apply an Unsatisfiable Budget
Set minAvailable equal to the replica count, which is the classic mistake:
# pdb-bad.yamlapiVersion: policy/v1kind: PodDisruptionBudgetmetadata: name: payments-api-pdbspec: minAvailable: 3 selector: matchLabels: app: payments-apikubectl apply -f pdb-bad.yamlkubectl get pdb# NAME MIN AVAILABLE MAX UNAVAILABLE ALLOWED DISRUPTIONS# payments-api-pdb 3 N/A 0ALLOWED DISRUPTIONS of 0 means no pod can be evicted right now.
Step 4 - Watch a Drain Get Blocked
Drain the node that runs one of the pods. Use a timeout so the command ends by itself:
NODE=$(kubectl get pod -l app=payments-api -o jsonpath='{.items[0].spec.nodeName}') kubectl drain $NODE --ignore-daemonsets --delete-emptydir-data --timeout=30s# evicting pod default/payments-api-...# error when evicting pods/"payments-api-..." (will retry after 5s):# Cannot evict pod as it would violate the pod's disruption budget.The drain keeps retrying until the timeout. Confirm why with the budget's live status:
kubectl get pdb payments-api-pdb -o yaml# status: currentHealthy: 3, desiredHealthy: 3, disruptionsAllowed: 0, expectedPods: 3kubectl get pods -l app=payments-apiStep 5 - Fix the Budget and Retry
Allow one pod to be unavailable at a time, then drain again:
# pdb-good.yamlapiVersion: policy/v1kind: PodDisruptionBudgetmetadata: name: payments-api-pdbspec: maxUnavailable: 1 unhealthyPodEvictionPolicy: AlwaysAllow selector: matchLabels: app: payments-apikubectl apply -f pdb-good.yamlkubectl get pdb# ALLOWED DISRUPTIONS should now be 1 kubectl drain $NODE --ignore-daemonsets --delete-emptydir-datakubectl get pods -l app=payments-api -o wide# The evicted pod was replaced on another node, and the service never dropped below 2 Ready podsThe unhealthyPodEvictionPolicy: AlwaysAllow setting lets Kubernetes evict pods that are already failing, so a crash-looping pod cannot block a drain forever.
Step 6 - Restore the Node
kubectl uncordon $NODEStep 7 - Protect a Quorum-Based StatefulSet
Databases and coordination services such as ZooKeeper have no load balancer to absorb a loss, and they need a quorum. A three-node ZooKeeper cluster needs two nodes to elect a leader, so allow only one to be down:
# zookeeper-pdb.yamlapiVersion: policy/v1kind: PodDisruptionBudgetmetadata: name: zookeeper-pdbspec: minAvailable: 2 selector: matchLabels: app: zookeeperFor Kafka, derive the budget from min.insync.replicas and the replication factor, so a drain cannot stop producers from writing.
Step 8 - Use an Upgrade Checklist
Before a cluster upgrade, find every budget that currently blocks disruptions:
# 1. List all PDBs with their allowed disruptionskubectl get pdb -A -o custom-columns=NS:.metadata.namespace,NAME:.metadata.name,ALLOWED:.status.disruptionsAllowed # 2. Show only blocking budgetskubectl get pdb -A --no-headers -o custom-columns=NS:.metadata.namespace,NAME:.metadata.name,ALLOWED:.status.disruptionsAllowed | awk '$3 == 0' # 3. For each one, compare Ready pods with the budgetkubectl get pods -n NAMESPACE -l LABEL-FROM-PDB-SELECTOR # 4. If pods are missing, scale up first, then drainkubectl scale deployment NAME --replicas=4 -n NAMESPACEStep 9 - Clean Up
kind delete cluster --name pdb-labProduction Best Practices & Common Pitfalls
Common MistakeCreating a PDB whose selector matches no pods. It exists but protects nothing. Check that
kubectl get pdbshows the expectedALLOWED DISRUPTIONS, and thatexpectedPodsin the status matches your replica count.
TipMake
maxUnavailable: 1the default for stateless services with more than one replica. It scales with the Deployment, it keeps drains moving, and it is the safest budget that still lets maintenance proceed.
RememberA PDB limits evictions, but it does not spread pods or guarantee capacity. Pair it with at least two replicas, a readiness probe, and topology spread or anti-affinity so one node never holds every replica.
- Never set a budget that cannot be met.
minAvailableequal to replicas,maxUnavailable: 0, or one replica withminAvailable: 1will stall upgrades. - Match selectors exactly. The PDB selector must match the pod template labels of the workload it protects, not the Deployment's own labels.
- Count only Ready pods. Unready pods reduce the healthy count, so a service with failing probes can block drains even when pods are running.
- Remember what bypasses PDBs. Direct pod deletion and Deployment rolling updates ignore the budget, so use rollout strategy settings for update safety.
- Review budgets before upgrades. Managed upgrades wait on blocking budgets and can time out, so run the checklist ahead of time.
- Keep one PDB per workload. Overlapping budgets on the same pods can make evictions fail with a configuration error.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
kubectl get pdb -n NS |
List budgets and allowed disruptions |
kubectl describe pdb NAME -n NS |
Show a budget's selector and status |
kubectl get pdb NAME -n NS -o yaml |
Read currentHealthy, desiredHealthy and disruptionsAllowed |
kubectl drain NODE --ignore-daemonsets --delete-emptydir-data |
Evict pods from a node |
kubectl uncordon NODE |
Make a drained node schedulable again |
kubectl scale deployment NAME --replicas=N -n NS |
Add replicas so a budget can be met |