Home KubernetesKubernetes Pod Disruption Budgets: Protect Your Workloads

Kubernetes Pod Disruption Budgets: Protect Your Workloads

by Knowledge Base Linux
kubernetes pod disruption budget keeping pods available during maintenance

Node upgrades, cluster autoscaling, and routine maintenance all evict pods, and without protection those voluntary evictions can take down your whole application at once. A Kubernetes pod disruption budget (PDB) sets a floor: it tells the cluster how many pods of a workload must stay available, and the eviction API refuses to go below that floor.

In this guide you will create PodDisruptionBudgets with both minAvailable and maxUnavailable, test them with a node drain, and learn the mistakes that make PDBs either useless or a blocker for your own maintenance.

kubernetes pod disruption budget node drain eviction illustration

What a Pod Disruption Budget Actually Controls

A PDB only constrains voluntary disruptions: evictions requested through the API, such as kubectl drain, cluster upgrades, and autoscaler scale-downs. It does not protect against involuntary disruptions like node hardware failure or a kernel panic. That distinction matters: a PDB guarantees availability during planned work, not immortality.

When an eviction would violate the budget, the API server returns a 429 error and the drain waits. This is by design. A PDB that is too strict will block your node upgrades, so the budget must reflect how many replicas you genuinely run.

Prerequisites

  • A Kubernetes cluster (version 1.21 or newer, where policy/v1 PDBs are stable) with kubectl configured.
  • A Deployment with at least two or three replicas to protect.
  • Cluster-admin or namespace edit permissions to create PDB objects.

Step 1: Create a Deployment to Protect

Deploy a small web workload if you do not already have one:

kubectl create deployment web --image=nginx:1.27 --replicas=3
kubectl expose deployment web --port=80
kubectl get pods -l app=web

Three replicas give the budget something meaningful to protect. A PDB on a single-replica workload can only ever allow zero disruptions, which blocks every drain.

Step 2: Create a PDB with minAvailable

The most common form guarantees a minimum number of healthy pods:

cat <<EOF | kubectl apply -f -
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: web-pdb
spec:
  minAvailable: 2
  selector:
    matchLabels:
      app: web
EOF
kubectl get pdb web-pdb

With three replicas and minAvailable: 2, the cluster allows at most one pod to be evicted at a time. During a drain, the evicted pod is rescheduled elsewhere before the next eviction is permitted, so at least two pods serve traffic throughout.

You can also express the floor as a percentage, which scales with replica count:

spec:
  minAvailable: 50%
  selector:
    matchLabels:
      app: web

Percentages round up for minAvailable, so 50% of three replicas still protects two pods.

Step 3: Use maxUnavailable Instead When It Fits Better

maxUnavailable caps how many pods may be down at once, which reads more naturally for large fleets:

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: web-pdb-max
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      app: web

For a ten-replica service, maxUnavailable: 2 lets maintenance proceed two pods at a time without ever dropping below eight. You must set exactly one of minAvailable or maxUnavailable; setting both is rejected. Whichever form you choose, the pod disruption budget is what turns an eviction request into a safe, gated operation instead of an immediate deletion.

Step 4: Test the PDB with a Node Drain

Pick a node running one of the web pods and drain it:

kubectl get pods -o wide -l app=web
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data

Watch the drain evict one pod and wait for its replacement to become ready before proceeding. Then verify the budget status:

kubectl describe pdb web-pdb

Check the Allowed disruptions field: it shows how many more evictions the budget currently permits. When the count is zero, further evictions will be refused with a 429 until a pod becomes healthy again.

When finished, return the node to service:

kubectl uncordon <node-name>

Step 5: Choose the Right Budget for Each Workload

  • Stateless web tiers: maxUnavailable: 1 or 25% keeps deploys fast while preserving capacity.
  • Quorum systems (etcd, databases): set minAvailable to quorum size, for example 2 of 3, so maintenance can never break consensus.
  • Single-replica workloads: do not create a PDB unless you accept that drains will block; scale to at least two replicas first.
  • Batch and cron workloads: PDBs still apply to pods selected by label, but short-lived jobs usually do not need one.

Troubleshooting Pod Disruption Budget Problems

Node drain hangs forever

Run kubectl get pdb -A and inspect ALLOWED DISRUPTIONS. A zero there means the budget is fully consumed, usually because a pod is unhealthy or stuck terminating. Fix the unhealthy pod first; the drain will proceed on its own.

PDB seems to do nothing

Confirm the selector actually matches pods: kubectl get pods -l app=web must return the pods you intend to protect. A label typo creates a pod disruption budget that protects nothing. Also remember that deleting a pod directly with kubectl delete pod bypasses the PDB entirely; only eviction API calls respect it.

Upgrades blocked across the whole cluster

Overly strict budgets compound: if every workload allows zero disruptions, no node can drain. During planned maintenance windows, temporarily relax budgets or accept that you must scale replicas up before draining.

Conclusion

A pod disruption budget is a one-object insurance policy for planned maintenance: it turns node drains and upgrades from availability gambles into controlled, one-pod-at-a-time operations. Start with maxUnavailable: 1 on stateless services and quorum-aware minAvailable on stateful ones, test with a real drain in staging, and watch ALLOWED DISRUPTIONS before every upgrade. Combine PDBs with readiness probes, covered in our guide to Kubernetes liveness and readiness probes, and with autoscaling from the Kubernetes HPA guide. The official Kubernetes PDB documentation details eviction semantics and edge cases.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.