0
0
Kubernetesdevops~5 mins

Pod Disruption Budgets in Kubernetes - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes, when you update or maintain your app, some parts stop working temporarily. Pod Disruption Budgets help keep enough parts running so your app stays available during these times.
When you want to update your app without making it unavailable to users.
When you need to do maintenance on your servers but want to keep your app running smoothly.
When you run multiple copies of your app and want to make sure not too many stop at once.
When you want to control how many app parts can be stopped during automatic system updates.
When you want to avoid downtime caused by unexpected restarts or crashes.
Config File - pdb.yaml
pdb.yaml
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: my-app-pdb
  namespace: default
spec:
  minAvailable: 2
  selector:
    matchLabels:
      app: my-app

This file tells Kubernetes to keep at least 2 pods with the label app: my-app running at all times. The minAvailable key sets the minimum number of pods that must stay up during disruptions. The selector finds the pods this rule applies to.

Commands
This command creates the Pod Disruption Budget in your Kubernetes cluster to protect your app pods during disruptions.
Terminal
kubectl apply -f pdb.yaml
Expected OutputExpected
poddisruptionbudget.policy/my-app-pdb created
This command checks the status of the Pod Disruption Budget to see how many pods are allowed to be disrupted.
Terminal
kubectl get poddisruptionbudget my-app-pdb
Expected OutputExpected
NAME MIN AVAILABLE MAX UNAVAILABLE ALLOWED DISRUPTIONS AGE my-app-pdb 2 N/A 0 10s
This command shows detailed information about the Pod Disruption Budget, including which pods it covers and current disruption status.
Terminal
kubectl describe poddisruptionbudget my-app-pdb
Expected OutputExpected
Name: my-app-pdb Namespace: default Min available: 2 Selector: app=my-app Status: Current Healthy: 3 Desired Healthy: 2 Disruptions Allowed: 1 Expected Pods: 3 Events: <none>
Key Concept

If you remember nothing else from this pattern, remember: Pod Disruption Budgets keep enough app parts running during updates or maintenance to avoid downtime.

Common Mistakes
Setting minAvailable higher than the total number of pods running.
This makes it impossible for Kubernetes to allow any disruptions, blocking updates or maintenance.
Set minAvailable to a number less than or equal to the total pods to allow safe disruptions.
Not matching the correct pod labels in the selector.
The Pod Disruption Budget won't protect the intended pods, risking downtime.
Use the exact labels that your app pods have in the selector section.
Summary
Create a Pod Disruption Budget YAML file to specify minimum pods that must stay running.
Apply the Pod Disruption Budget with kubectl to protect your app during disruptions.
Check the Pod Disruption Budget status and details to monitor allowed disruptions.