Unable to drain AKS node due to pdb with 50% maxUnavailable

Tanul 1,291 Reputation points
2024-08-01T05:27:26.1766667+00:00

What is the problem with this config.

Whenever I run kubectl drain <node> this error is coming: "Cannot evict pod as it would violate the pod's disruption budget"

How to resolve it.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment2
spec:
  replicas: 20
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  selector:
    matchLabels:
      app: nginx2
  template:
    metadata:
      labels:
        app: nginx2
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: pdb-nginx2
spec:
  maxUnavailable: 50%
  selector:
    matchLabels:
      app: nginx2
Azure Kubernetes Service
Azure Kubernetes Service
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,459 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Abiola Akinbade 29,490 Reputation points Volunteer Moderator
    2024-08-01T10:00:17.6366667+00:00

    Hello Tanul,

    Thanks for your question.

    Your deployment is maxUnavailable: 25% and PodDisruptionBudget is maxUnavailable: 50 percent (which means that at most 50% of the pods can be unavailable at any given time). With 20 replicas, 50% maxUnavailable means 10 pods can be unavailable.

    Try this:

    apiVersion: policy/v1
    kind: PodDisruptionBudget
    metadata:
      name: pdb-nginx2
    spec:
      maxUnavailable: 75%
      selector:
        matchLabels:
          app: nginx2
    
    
    

    You can mark it 'Accept Answer' and 'Upvote' if this helped you

    Regards,

    Abiola

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.