Unable to drain AKS node due to pdb issue

Tanul 1,281 Reputation points
2024-07-31T12:16:27.3933333+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"

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment1
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  selector:
    matchLabels:
      app: nginx1
  template:
    metadata:
      labels:
        app: nginx1
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: pdb-nginx1
spec:
  minAvailable: 1
  selector:
    matchLabels:
      app: nginx1

-------


apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment4
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nginx4
  template:
    metadata:
      labels:
        app: nginx4
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: pdb-nginx4
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      app: nginx4


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 (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,156 questions
0 comments No comments
{count} votes

Accepted answer
  1. akinbade abiola 18,465 Reputation points
    2024-07-31T12:52:55.6533333+00:00

    Hello Tanul,

    You have set 1 replica, so only one pod is running but your The RollingUpdate strategy allows for 25% unavailability which is 25 percent of a pod rounded down to 0. When you drain the node, it attempts to evict the pod. but you have one replica and the PDB requires one pod to always be available, hence it can't evict the pod without violating the PDB.

    To solve you can either increase replicas, adjust the pdb or remove the pdb if you do not need it.

    https://learn.microsoft.com/en-us/troubleshoot/azure/azure-kubernetes/create-upgrade-delete/error-code-unsatisfiablepdb?source=recommendations

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

    Regards,

    Abiola


0 additional answers

Sort by: Most helpful

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.