Skip to content

PodDisruptionBudget (PDB) in Kubernetes

A PodDisruptionBudget (PDB) is a Kubernetes resource that helps ensure a certain number or percentage of Pods remain available during voluntary disruptions. These disruptions can include node maintenance, cluster scaling, or rolling updates.


Purpose of PodDisruptionBudget

  • To protect application availability during planned events.
  • To enforce a minimum number of Pods running or restrict the maximum number of Pods disrupted simultaneously.
  • To balance the needs of system administrators and application reliability.

Key Features

  1. Voluntary Disruptions:

  2. PDB applies only to voluntary disruptions, such as:

    • Node draining for maintenance.
    • Rolling updates.
    • Scaling events.
  3. Minimum Availability:

  4. Ensures that a certain number of Pods remain available during disruptions.

  5. Maximum Disruption:

  6. Restricts the maximum number of Pods that can be disrupted simultaneously.

  7. Integration with Controllers:

  8. Works with Deployments, StatefulSets, ReplicaSets, and other controllers.

How PodDisruptionBudget Works

  • minAvailable:

  • Specifies the minimum number of Pods that must remain available during disruptions.

  • maxUnavailable:

  • Specifies the maximum number of Pods that can be disrupted simultaneously.

  • Scope:

  • PDB is applied to a group of Pods matching the specified label selector.

Example PodDisruptionBudget

1. Minimum Available Pods

This PDB ensures at least 2 Pods are always running during voluntary disruptions.

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

2. Maximum Unavailable Pods

This PDB ensures that no more than 1 Pod can be disrupted at any time.

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

Use Cases

  1. High Availability:

  2. Ensures critical applications remain operational during cluster maintenance.

  3. Rolling Updates:

  4. Controls the pace of Pod evictions to prevent service downtime.

  5. Stateful Applications:

  6. Protects databases or StatefulSets that require a specific number of Pods for consistency.

Best Practices

  1. Plan for Downtime:

  2. Use minAvailable or maxUnavailable based on the application’s availability requirements.

  3. Label Pods Consistently:

  4. Ensure Pods have appropriate labels to match the PDB’s selector.

  5. Combine with Monitoring:

  6. Use monitoring tools to track PDB effectiveness during disruptions.

  7. Test Scenarios:

  8. Simulate node drains and rolling updates to verify PDB behavior.

Limitations

  1. Voluntary Disruptions Only:

  2. PDB does not apply to involuntary disruptions, such as crashes or node failures.

  3. No Guarantee of Scheduling:

  4. PDB ensures Pods are not evicted below the threshold but does not guarantee new Pods can be scheduled.

Conclusion

PodDisruptionBudget is a vital tool in Kubernetes for ensuring application availability during planned events like maintenance or updates. By setting appropriate thresholds with minAvailable or maxUnavailable, you can balance operational flexibility with application reliability.