🛡️
Kubernetes

Pod Disruption Budget (PDB)

Keep minimum pods available during node drains and cluster upgrades

📋Configuration Files

pdb.yml

PDB for Deployment — at least 1 pod available during voluntary disruptions

yaml
1apiVersion: policy/v1
2kind: PodDisruptionBudget
3metadata:
4 name: myapp-pdb
5 namespace: apps
6spec:
7 minAvailable: 1
8 selector:
9 matchLabels:
10 app: myapp
11---
12# Alternative: maxUnavailable for large fleets
13# spec:
14# maxUnavailable: 1
15# selector:
16# matchLabels:
17# app: myapp

deployment-with-labels.yml

Deployment labels must match PDB selector

yaml
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: myapp
5 namespace: apps
6spec:
7 replicas: 3
8 selector:
9 matchLabels:
10 app: myapp
11 template:
12 metadata:
13 labels:
14 app: myapp
15 spec:
16 containers:
17 - name: app
18 image: myapp:latest
19 ports:
20 - containerPort: 8080
21 readinessProbe:
22 httpGet:
23 path: /health
24 port: 8080
25 initialDelaySeconds: 10
26 livenessProbe:
27 httpGet:
28 path: /health
29 port: 8080
30 initialDelaySeconds: 30
📄

Step 01

Apply PDB

(01)Apply manifests

Linux
1kubectl apply -f deployment-with-labels.yml
2kubectl apply -f pdb.yml
3kubectl get pdb -n apps
4kubectl describe pdb myapp-pdb -n apps

(02)Test drain respects PDB

Linux
1# voluntary disruption — should respect minAvailable
2kubectl drain <node> --ignore-daemonsets --delete-emptydir-data
3# undo: kubectl uncordon <node>