Pod Disruption Budgets: Availability Assurance
Creating a Pod Disruption Budget
To better understand how to create a PDB for your application, let's consider the following example:
We have a critical application deployed as a Deployment named hello-world with 5 replicas.
kubectl apply -f - <
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
spec:
replicas: 5
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: gcr.io/google-samples/hello-app:1.0
ports:
- containerPort: 8080
EOF
After many tests and considerations, you have decided that during disruptions, 3 replicas should always be available. To enforce this rule, the PDB can be created using the following command:
kubectl create pdb hello-world --selector app=hello-world --min-available 3
A PDB, like ClusterIP, uses labels to select the Pods to which it applies. In this case, we used the label app=hello-world to select all Pods of the Deployment hello-world. It also accepts two parameters to define the availability rules: --min-available and --max-unavailable. In this case, we used --min-available 3, which means that at least 3 Pods must be available at all times.
You can verify that it was created successfully by running the following command:
Cloud-Native Microservices With Kubernetes - 2nd Edition
A Comprehensive Guide to Building, Scaling, Deploying, Observing, and Managing Highly-Available Microservices in KubernetesEnroll now to unlock all content and receive all future updates for free.
