Video in progress

Strong Middle 🧩 Microservices

What is a PodDisruptionBudget, and what do you do so your service doesn't go down during a node drain or a cluster upgrade?

A PDB limits how many pods can be evicted at the same time during voluntary disruptions (node drain, cluster upgrade, the autoscaler removing a node). But it is only half the protection: if the pods aren't spread across nodes and zones, they all go anyway when one node dies.

📖 Answer

The situation: payment-service has 3 replicas. The ops team upgrades nodes at night, and kubectl drain runs one after another. The scheduler placed all three pods on two nodes. The first drain evicts 2 pods at once, and the third carries the load alone until the new pods come up, and falls over.

With a PDB:

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: payment-service
spec:
  minAvailable: 2          # or maxUnavailable: 1
  selector:
    matchLabels:
      app: payment-service

Now if a drain tries to evict a second pod, the eviction API rejects it. The drain waits until a new pod replacing the first is ready (readiness) and tries again.

Pitfalls:

  • replicas: 1 with minAvailable: 1: the drain hangs forever because not a single pod can be evicted. The ops team hates this and ends up deleting the PDB. For a single-replica service, the fix is a second replica, not a PDB.
  • A PDB doesn't protect against involuntary disruptions (a node suddenly dying, an OOM).
  • If readiness is wrong, the PDB miscounts the "ready" pods too.

For spreading the pods:

topologySpreadConstraints:
  - maxSkew: 1
    topologyKey: topology.kubernetes.io/zone
    whenUnsatisfiable: ScheduleAnyway
    labelSelector:
      matchLabels: { app: payment-service }

Graceful shutdown is needed as well: a drain sends SIGTERM to the pod, and the application has to finish the requests it is handling before exiting.