'How the Kubernetes pdb works?
I was trying to implement the pdb in kubernetes for our application. but I am confused with How the PDB and HPA are together related or If rolling update strategy is defined is there any dependency with PDB ?
apiVersion: apps/v1
kind: Deployment
metadata:
name: pdbtest
namespace: test-fix
labels:
app: pdbtest
environment: dev
spec:
replicas: 4
strategy:
type: "RollingUpdate"
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
selector:
matchLabels:
app: pdbtest
template:
metadata:
labels:
app: pdbtest
environment: dev
spec:
containers:
- name: pdbtest
image: nginx
imagePullPolicy: "Always"
ports:
- name: http
containerPort: 8080
protocol: TCP
resources:
requests:
memory: 256Mi
cpu: 0.2
limits:
memory: 2048Mi
cpu: 1
env:
- name: APPLICATIONNAME
value: pdbtest
nodeSelector:
agentpool: devpool01
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: pdbtest
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: pdbtest
maxReplicas: 6
minReplicas: 4
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
labels:
app: pdbtest
name: pdbtest
namespace: test-fix
spec:
minAvailable: 4
selector:
matchLabels:
app: pdbtest
In order to test the pdb behavior , I just tried to delete multiple pods, But what i expected is, pdb will block the deletion of the pods as its expected 4 replicas always available as per the pdb, but actually 4new pods are getting created.
So would like to understand How pdb works? whether its applicable for deleting pods/deployments or rolling update? How the PDB related to HPA. if we are planning for a pdb with minAvailable property, then what value for the minAvailable in PDB will be considered ? (is it same as hpa minpods or it should be less than the minpods in HPA)? Will PDB have impact on new release rolling update? How PDB is different from Rolling Update strategy?
Solution 1:[1]
If you read the documentation, you find a disclaimer that is applicable to your test scenario.
Caution: Not all voluntary disruptions are constrained by Pod Disruption Budgets. For example, deleting deployments or pods bypasses Pod Disruption Budgets.
That's why you could delete it. Apart from that, it's different from min replicas of an HPA in that it will provide protection against disruptions, in certain scenarios. For example, when you drain a node.
For your test, you could create a deployment with 6 replicas and create a disruption budget of 4 pods. Finally, try to update the deployment to a replica count of 2.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
