Review Kubernetes Deployment PodDisruptionBudget configuration

Set an acceptable level of voluntary disruption for maintenance.

Description

A PodDisruptionBudget (PDB) limits how many Deployment Pods can be evicted through the Eviction API during work such as a node drain. Node failures, direct Pod deletion and Deployment rolling updates fall outside that protection.

Potential impact

Evicting too many replicas can slow or interrupt service. A budget with no room for eviction can stall maintenance.

Remediation

  • In the Deployment’s namespace, select its Pod labels and set either minAvailable or maxUnavailable for the number of replicas the service needs.
  • Check readiness and replacement capacity, then test a drain. Configure the Deployment’s rolling-update strategy and spread Pods across failure domains separately.

Examples

Use a maintained, verified image in place of the historical nginx version.

Before

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.14.2

This manifest shows three replicas. Check whether a PDB in the same namespace already selects them.

After

yaml
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: nginx-pdb
spec:
  minAvailable: 2
  selector:
    matchLabels:
      app: nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.14.2

The PDB selects app: nginx Pods. With minAvailable: 2, evicting a healthy Pod must leave at least two available.

References