Using PodDisruptionBudgets
TOC
Understanding PodDisruptionBudgetsCreating PodDisruptionBudgetsCreating a PDB by using CLIPrerequisitesYAML file exampleCreating a PDB via YAMLManaging a PDB by using CLIViewing a PDBUpdating a PDBDeleting a PDBWhen to use a PodDisruptionBudgetUnderstanding PodDisruptionBudgets
Refer to the official Kubernetes documentation: Specifying a Disruption Budget for your Application
A PodDisruptionBudget (PDB) allows you to limit the disruption to your application when its pods need to be rescheduled for some reason such as upgrades or routine maintenance work on the Kubernetes nodes.
As a cluster administrator or application owner, you can create a PodDisruptionBudget for each application. A PDB limits the number of Pods of a replicated application that are down simultaneously from voluntary disruptions. For example, a quorum-based application would like to ensure that the number of replicas running is never brought below the number needed for a quorum. A web front end might want to ensure that the number of replicas serving load never falls below a certain percentage of the total.
By using PodDisruptionBudgets, you can:
- Ensure High Availability: Maintain a minimum number of available replicas during node maintenance, cluster upgrades, or other voluntary disruptions.
- Control Disruption Impact: Define exactly how much disruption an application can tolerate by specifying
minAvailableormaxUnavailable. - Safely Drain Nodes: During operations like
kubectl drain, the system respects PDBs and waits until Pods can be safely evicted without violating the disruption budget.
How it works:
- You define a PodDisruptionBudget resource targeting a specific set of Pods using a label selector.
- You specify either
minAvailable(minimum number or percentage of Pods that must remain available) ormaxUnavailable(maximum number or percentage of Pods that can be concurrently unavailable). - When a voluntary disruption occurs (like draining a node for an OS upgrade), the eviction API checks the PDB. If evicting the Pod would violate the budget, the eviction is blocked or delayed until enough Pods are available again.
Creating PodDisruptionBudgets
Creating a PDB by using CLI
Prerequisites
- Ensure you have
kubectlconfigured and connected to your cluster. - You must have an application running with multiple replicas (like a Deployment or StatefulSet).
YAML file example
Creating a PDB via YAML
The output will show the allowed disruptions, minimum available, and current healthy pods.
Managing a PDB by using CLI
Viewing a PDB
-
List all PDBs in a namespace:
-
Get detailed information about a specific PDB:
Updating a PDB
You can update a PDB by editing its configuration. For instance, to change minAvailable:
Modify the minAvailable or maxUnavailable fields, save, and exit.
Deleting a PDB
If you no longer need to protect the workload with a PDB, you can safely delete it:
Deleting the PDB will not affect the actual running application, it only removes the disruption budget constraints for node maintenance and eviction processes.
When to use a PodDisruptionBudget
You should consider using a PDB when:
- Your application requires a strict minimum number of replicas to handle traffic or maintain quorum (e.g., ZooKeeper, Elasticsearch).
- You are running workloads on a cluster where cluster administrators frequently perform node upgrades or scaling operations.
- You want to ensure zero-downtime during voluntary disruptions such as node drains.
A PDB is NOT helpful for involuntary disruptions (e.g., node hardware failure, kernel panic), as those cannot be delayed or prevented by Kubernetes.