Review StatefulSet PodDisruptionBudget settings

Configure a disruption budget to retain required replicas during planned maintenance.

Description

A PodDisruptionBudget (PDB) limits voluntary evictions of StatefulSet Pods through the Eviction API, including node drains. Node failures, direct Pod deletion and StatefulSet rolling updates fall outside its scope.

Potential impact

Draining too many replicas can interrupt service or break quorum. A strict budget or too little replacement capacity can stall the drain.

Remediation

  • In the StatefulSet’s namespace, select its Pod labels. Set either minAvailable or maxUnavailable to preserve the replicas the service or quorum needs.
  • Check readiness and replacement capacity, then test a drain. Plan recovery, replica placement and rolling updates separately.

Examples

Provide the nginx headless Service for this StatefulSet.

Before

yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: nginx
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.25

The excerpt defines three replicas. Check whether an existing PDB already selects them.

After

yaml
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: web-pdb
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: nginx
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.25

For the app: nginx Pods, maxUnavailable: 1 allows one unavailable replica. A replica that is already unavailable uses that allowance.

References