Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 422 of 8026. Kubernetes Traffic and ScalingFree lesson

Managing Disruptions with Pod Disruption Budgets

You will define Pod Disruption Budgets to ensure that critical services remain available during automated node scaling and maintenance events.

In this lesson, you will learn how to use Pod Disruption Budgets (PDBs) to maintain service availability during voluntary disruptions like cluster upgrades or node maintenance.

When you manage a cluster, the Cluster Autoscaler or manual node drain operations need to remove Pods to free up resources or update underlying node images. If you have a critical microservice running three replicas, a naive node drain might move all three at once, causing a service outage. A Pod Disruption Budget (PDB) acts as a safety contract between your application and the cluster administrator, ensuring that a minimum number of replicas remain "up" at all times.

Defining the Budget

A PDB is a Kubernetes object that specifies either a minAvailable number of pods or a maxUnavailable percentage. The Kubernetes API will refuse to evict any Pod that would cause your service to drop below this defined threshold.

Here is a simple example for a deployment that requires at least two healthy replicas to handle production traffic:

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: web-app-pdb
spec:
  minAvailable: 2
  selector:
    matchLabels:
      app: web-server

How It Works

When you initiate a kubectl drain on a node, the operation doesn't just forcefully terminate pods. It checks the PDB. If your web-app has three replicas and a minAvailable: 2, the cluster will allow the eviction of exactly one Pod. If you attempt to evict a second Pod while the first is still pending or initializing, the request will be rejected.

This mechanism is vital for cloud-native architectures because it shifts the responsibility of availability from manual coordination to automated policy enforcement. Whether you are scaling down nodes to save costs or performing a rolling cluster update, the PDB ensures that your service remains available for incoming requests, effectively bridging the gap between infrastructure maintenance and application uptime requirements.

Key Takeaway: Pod Disruption Budgets protect your application from downtime during voluntary maintenance by enforcing a minimum number of healthy replicas that the cluster must respect before evicting any pods.