Skip to content

Kubernetes Pod Disruption Budget: From YAML to a Safe Drain

What a Kubernetes Pod Disruption Budget protects, how to size minAvailable or maxUnavailable, and why a node drain stalls when allowed disruptions hit zero.

Published
Topics
KubernetesInfrastructure
Dark blue cover with the Log'in Line logo and the title Kubernetes Pod Disruption Budget: From YAML to a Safe Drain

You're upgrading a node pool, or your cloud provider is doing it for you, and someone on the team asks the reasonable question: "Will the API stay up while nodes get recycled?" Somewhere in the chart there's a PodDisruptionBudget. Nobody remembers who wrote it, or what it actually promises.

A Pod Disruption Budget (PDB) tells Kubernetes how many pods of an application can be taken down on purpose at the same time. It applies to evictions, the polite "please leave" requests that kubectl drain, node upgrades and the cluster autoscaler send through the Eviction API. It doesn't stop a node from crashing, and it doesn't slow down your own rollouts. Sized right, it lets you drain nodes in the middle of the day. Sized wrong, it turns a 20-minute upgrade into a drain that never finishes.

Think of it as the rule at a busy coffee shop: "at least two baristas on the bar at all times." The manager can send people on break, one at a time, as long as two stay behind the counter. The rule can't cure a barista who calls in sick. And the new hire who showed up but hasn't put the apron on yet doesn't count. That's the whole PDB in three sentences; the rest of this post unpacks them.

What a Pod Disruption Budget protects

When you run kubectl drain, kubectl doesn't delete pods. It asks the API server to evict each one. The API server checks the PDBs and answers with one of three codes, as the API-initiated eviction docs describe: 200 (go ahead), 429 (not right now, the budget is spent) or 500 (misconfiguration, like two PDBs selecting the same pod).

That's the key to everything else: a PDB only guards the eviction door. The Disruptions page splits the world like this:

What happens to the podDoes the PDB block it?What protects you instead
kubectl drain, managed node upgrades, autoscaler scale-downYes, through the Eviction APIThe PDB, then your provider's timeout
Node crash, kernel panic, VM deleted, node-pressure evictionNo, but the lost pod counts against the budgetReplica count and pod placement
kubectl delete pod, deleting the Deployment, rolling out a new versionNoThe controller's own strategy (maxSurge, maxUnavailable on the Deployment)

Two things follow. Your PDB will never block a rollout, which is good news. But an unplanned node failure eats into the budget, so a drain right after an outage can find nothing left to spend. It's a bouncer at the exit door. The windows are someone else's problem.

Managed clouds also put a clock on it. During surge upgrades, GKE respects PDBs for up to one hour and then removes the remaining pods. On EKS, a managed node group update fails with PodEvictionFailure if pods haven't left a node within 15 minutes, unless you pass the force flag. So in practice, your PDB decides how fast maintenance can go, and whether it ends cleanly or with a forced deletion.

A PDB starts with the capacity your workload needs

A PDB uses either minAvailable (how many must stay) or maxUnavailable (how many may go), never both. Percentages are allowed, and Kubernetes always rounds up, per the PDB configuration guide. That rounding is where most surprises come from. Here's how many evictions each setting allows when every replica is Ready:

Setting1 replica2 replicas3 replicas
minAvailable: 10 (drain stalls)12
minAvailable: 200 (drain stalls)1
minAvailable: "50%"0 (50% of 1 rounds up to 1)11 (50% of 3 rounds up to 2)
maxUnavailable: 1111
maxUnavailable: "30%"1 (30% of 1 rounds up to 1: that's 100%)11
maxUnavailable: 0000

The last row blocks every drain, forever, by design. The row above it is the trap pointing the other way: maxUnavailable: "30%" sounds careful, yet on a single replica it happily lets the only pod go.

For quorum systems the math changes: with five etcd, ZooKeeper or Consul members, maxUnavailable: 1 or minAvailable: 3 keeps a majority. For a single-instance app, there's no clever number. Either the PDB blocks everything or it protects nothing. The real decision is adding a replica or scheduling a short outage. We hit this while moving a client's production API onto Kubernetes: it ran a single replica because the database capped connections at 200, and the chart shipped a PDB with minAvailable: 1. No node could drain. Our engineer disabled the PDB for the cutover and put it to the client this way: with ten pods and a PDB of 1, some version of the API is always serving while the others update; with one pod, the PDB doesn't protect anything, it just pins the node.

A policy/v1 example for a three-replica Deployment

For most stateless services we default to maxUnavailable: 1. It follows the replica count when the HPA scales, which is also what the Kubernetes docs recommend.

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: api-pdb
  namespace: prod
spec:
  maxUnavailable: 1
  unhealthyPodEvictionPolicy: AlwaysAllow
  selector:
    matchLabels:
      app: api   # must match the Deployment's selector exactly

The selector deserves more attention than it usually gets. In policy/v1, an empty selector (selector: {}) matches every pod in the namespace. A typo in a label gives you a budget that protects nothing. And if two PDBs select the same pod, the API returns a 500 ("This pod has more than one PodDisruptionBudget") and kubectl drain gives up instead of retrying. This one shows up a lot with database operators: CloudNativePG, for example, creates two PDBs per Postgres cluster on its own. Adding yours on top is how you get the overlap. A quick look before writing anything:

$ kubectl get pdb -A -o custom-columns=NS:.metadata.namespace,NAME:.metadata.name,SELECTOR:.spec.selector

maxUnavailable and percentages also need a known controller (Deployment, StatefulSet, ReplicaSet, or a custom resource with a scale subresource). For bare pods, only an integer minAvailable works.

Why a node drain stalls with zero allowed disruptions

Here's what a stalled drain looks like. kubectl retries every five seconds, and its default timeout is infinite, so it will happily do this all night:

$ kubectl drain pool-a-node-1 --ignore-daemonsets --delete-emptydir-data
node/pool-a-node-1 cordoned
evicting pod prod/api-7d9c6b5f4-x2k8p
error when evicting pods/"api-7d9c6b5f4-x2k8p" -n "prod" (will retry after 5s): Cannot evict pod as it would violate the pod's disruption budget.
error when evicting pods/"api-7d9c6b5f4-x2k8p" -n "prod" (will retry after 5s): Cannot evict pod as it would violate the pod's disruption budget.

The PDB status tells you why in four numbers:

$ kubectl get pdb api-pdb -n prod -o yaml
...
status:
  currentHealthy: 2
  desiredHealthy: 2
  disruptionsAllowed: 0
  expectedPods: 3

expectedPods is what the controller wants (3). currentHealthy counts pods whose Ready condition is true (2). desiredHealthy is the floor your rule sets (2). disruptionsAllowed is the gap between the last two, never below zero. From there, four situations cover nearly every stall:

What you seeWhat it meansThe way out
currentHealthy equals expectedPods, disruptionsAllowed: 0The rule is too strict for the replica countAdd a replica or loosen the threshold
currentHealthy lower than expectedPodsA pod is Running but not Ready (failing probe, CrashLoopBackOff)Fix the pod, or set AlwaysAllow
A new pod stuck in PendingThe replacement has nowhere to goAdd capacity, check affinity and taints
expectedPods: 0The selector matches nothingFix the labels

The second case is the sneaky one, because the PDB itself is perfectly reasonable. The budget was already spent by the sick pod. It's the barista without an apron: present, not serving.

$ kubectl get pods -n prod -l app=api   # one of these is 0/1 Ready
$ kubectl get pods -A --field-selector=status.phase=Pending

A drain test that proves the budget works

The best time to learn your PDB blocks drains is on a throwaway cluster, not during the maintenance window. A kind cluster is enough. The setup: three replicas, the PDB above without the unhealthyPodEvictionPolicy line, one pod with a deliberately broken readiness probe, and a drain on the node it runs on:

$ kubectl get pdb api-pdb
NAME      MIN AVAILABLE   MAX UNAVAILABLE   ALLOWED DISRUPTIONS   AGE
api-pdb   N/A             1                 0                     2m

$ kubectl drain <node> --ignore-daemonsets --timeout=60s
...(will retry after 5s): Cannot evict pod as it would violate the pod's disruption budget.

With the default policy, IfHealthyBudget, a Running-but-not-Ready pod can only be evicted when the app is healthy overall. It isn't, because of that very pod, so the drain waits for a recovery that may never come.

With unhealthyPodEvictionPolicy: AlwaysAllow (stable since Kubernetes 1.31, on by default since 1.27), the same drain behaves differently: the unready pod gets evicted right away, while the two healthy ones stay protected. The safe drain guide recommends this setting so a crashlooping app can't hold a node hostage. It isn't extra capacity, though. It doesn't make the app more available; it stops an already useless pod from blocking the drain.

Save both outputs in your runbook. The engineer doing the next upgrade at 9 p.m. will thank you.

Waiting skeleton meme: kubectl drain still waiting for the crashlooping pod to become Ready

The checklist before a node pool upgrade

A PDB handles "how many." It says nothing about "where." A client's CTO once asked us the uncomfortable question: what good are three replicas and a 33% PDB if all three pods sit on the node you're draining? The PDB rations the evictions, and the refused pods wait until their replacements are Ready elsewhere. Nobody goes down, but everything depends on free room on other nodes.

We always set anti-affinity on cluster add-ons. On applications we used to skip it, worried about pods stuck in Pending on a tight cluster. Our compromise is preferred anti-affinity: spread pods when possible, schedule them anyway when not. topologySpreadConstraints do the same job with more control, especially across zones.

affinity:
  podAntiAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 100
        podAffinityTerm:
          topologyKey: kubernetes.io/hostname
          labelSelector:
            matchLabels:
              app: api

Databases get their own rules. A node pool migration of ours once stalled on a two-pod PostgreSQL cluster: with two instances, the PDB couldn't let anything go. We recommended moving to three, and that third instance is what makes daytime maintenance possible. On clusters that host databases, our routine is: create the new node pool, drain the old nodes one at a time, let the operator reschedule pods and confirm failover, then delete the old pool. We also pause the operator before a Kubernetes version upgrade. The team's verdict, roughly translated: "it's a pain, but as long as we run databases in the cluster, we don't get a choice."

And one we learned the hard way: don't copy production PDBs into dev. At one client, identical PDBs across all environments (for chart consistency) blocked a scale operation on a non-production Elasticsearch, and in the confusion one of our engineers scaled down the wrong environment. We removed PDBs from dev. CloudNativePG gives the same advice for single-instance dev clusters.

Before each node, the checklist fits on a sticky note:

  1. Every PDB shows ALLOWED DISRUPTIONS above zero: kubectl get pdb -A.
  2. No pod is Running but not Ready in a protected app.
  3. There's room for the replacements, and nothing is Pending.
  4. Replicas are spread across nodes (and zones, if you have them).
  5. Database failover is confirmed before you touch the node running the primary.
  6. You know your provider's timeout: one hour on GKE surge upgrades, 15 minutes per node on EKS managed node groups.

If you're planning the version upgrade itself, our post on Kubernetes end of life dates covers the deadlines per cloud. And this is the kind of work we do every week on the 50 or so infrastructures we run through managed Kubernetes: reviewing PDBs, checking pod placement, and running node upgrades during business hours. If your last drain ended with the same line repeating every five seconds, we're happy to look at your PDBs together during a free 30-minute assessment call.

About the author

Bastien Genestal

Lead Cloud Architect @ Log'in Line

As Lead Cloud Architect, I manage a team of architects and SREs to manage our clients' clusters on a daily basis. I am also a big fan of climbing

Get a full team for the price of a part-time freelancer.

Contact us
infra@loginline.com
No commitmentOn-call included