> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# kubectl drain Hangs on the Last Pod

> Explains why kubectl drain hangs when a PodDisruptionBudget blocks eviction and how to diagnose and fix it by scaling replicas, relaxing the PDB or force deleting as last resort.

Scenario: you run `kubectl drain` on a node that has 12 pods. Eleven pods evict normally, but one pod remains on the node and the drain never completes.

```bash theme={null}
kubectl drain node-1
```

Why does this happen and how do you fix it?

## What kubectl drain does

`kubectl drain` uses the Eviction API to evict every evictable pod from a node so workloads can be rescheduled elsewhere. This is typically done before maintenance (patching, rebooting, or decommissioning a node) so no pods are left running on the node.

When a single pod remains after a drain, the most common cause is a PodDisruptionBudget (PDB) preventing eviction.

## PodDisruptionBudget (PDB) — the usual culprit

A PodDisruptionBudget declares how many pods of an application must stay available during voluntary disruptions (like node drains). If a PDB requires at least one pod and your cluster currently has only one replica, the Eviction API will refuse the eviction because it would violate the PDB.

Example PDB that blocks eviction of the last replica:

```yaml theme={null}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: my-app-pdb
spec:
  minAvailable: 1
  selector:
    matchLabels:
      app: my-app
```

If there is only one pod matching `app: my-app`, evicting it would reduce `available` to 0, so eviction is denied and the pod stays on the node.

The other 11 pods were evicted because they either had no restrictive PDB or they belonged to controllers with replicas already available on other nodes.

## How to diagnose the blocking PDB and pod

Run these commands to find the PDBs and related pods:

```bash theme={null}
kubectl get poddisruptionbudgets
kubectl describe poddisruptionbudget my-app-pdb
kubectl get pods -l app=my-app -o wide
```

Also check whether the stuck pod is managed by a controller (Deployment, ReplicaSet, StatefulSet) or is a bare pod:

```bash theme={null}
kubectl get pod my-app-abcdef -o yaml
```

If the pod is unmanaged (no ownerReferences), it will not be recreated elsewhere after eviction.

## Safe remediation steps

1. Scale the workload so the PDB can be satisfied, then drain:
   * For a Deployment:
     ```bash theme={null}
     kubectl scale deployment my-app --replicas=2
     ```
   * For a StatefulSet:
     ```bash theme={null}
     kubectl scale statefulset my-stateful-app --replicas=2
     ```

2. Once the additional replica is ready, run:
   ```bash theme={null}
   kubectl drain node-1
   ```

3. If you cannot scale (emergency maintenance), consider:
   * Temporarily relaxing the PDB (for example, set `minAvailable: 0` or change to `maxUnavailable`), then restore it after maintenance.
   * Cordoning the node (`kubectl cordon node-1`) and performing a controlled shutdown if you accept the risk.
   * As a last resort, force-delete the pod (see warning below).

## Force deletion (last resort)

Force-deleting bypasses the Eviction API and PDB checks — it removes the Pod API object immediately but does not guarantee the container process on the node has stopped. Use only when you fully understand the risk.

```bash theme={null}
kubectl delete pod my-app-abcdef --grace-period=0 --force
```

Force-deleting a pod can lead to split-brain or data corruption for stateful workloads (databases, etc.). It does not ensure the container process has stopped on the node, so you may end up with two active copies of the same stateful service.

## Recommended safe approach (step-by-step)

1. Inspect PDBs and determine which one is blocking eviction.
2. Scale up the controller (Deployment/StatefulSet/ReplicaSet) so PDB constraints can be satisfied.
3. Verify the new replica is ready.
4. Run `kubectl drain node-1`.
5. After maintenance, scale replicas back to the desired count and restore any modified PDBs.

![A stylized diagram of a Kubernetes cluster showing the control plane (API server and etcd) at the top and three worker nodes with multiple pods, including a highlighted postgres pod. Large teal text on the left reads "ADD A SECOND REPLICA."](https://mintcdn.com/kodekloud-c4ac6d9a/IK4ISE2GFis3psR1/images/DevOps-Interview-Questions-and-Answers-Scenario-Based-Prep/Kubernetes/kubectl-drain-Hangs-on-the-Last-Pod/k8s-cluster-controlplane-workers-postgres-replica.jpg?fit=max\&auto=format\&n=IK4ISE2GFis3psR1\&q=85\&s=f643d97906499f6c2d702035d3765960)

If a pod is not managed by a controller (a “bare” pod) it will not be recreated elsewhere after eviction. Ensure pods are managed by a Deployment/StatefulSet/ReplicaSet so replacements are created automatically when evicted.

## Quick reference table

| Task | Command / Example | Purpose |
| - | - | - |
| Drain a node | `kubectl drain node-1` | Evict evictable pods before maintenance |
| List PDBs | `kubectl get poddisruptionbudgets` | Find PDBs that may block eviction |
| Describe a PDB | `kubectl describe poddisruptionbudget my-app-pdb` | See which pods are protected |
| Scale a Deployment | `kubectl scale deployment my-app --replicas=2` | Add replica(s) to satisfy PDB |
| Force-delete pod (danger) | `kubectl delete pod my-app-abcdef --grace-period=0 --force` | Remove pod bypassing PDB (use only as last resort) |

## Summary

* A single pod remaining during `kubectl drain` is most often caused by a PodDisruptionBudget that prevents eviction.
* The safest fix is to increase replicas so the PDB can be satisfied, then drain the node.
* Avoid force-deleting pods for stateful workloads unless you accept the risk and understand the consequences.

## Links and references

* [Kubernetes: PodDisruptionBudget documentation](https://kubernetes.io/docs/concepts/workloads/pods/disruptions/)
* [Kubernetes: kubectl drain](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#drain)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/devops-interview-prep/module/60905e58-3a8e-4423-9743-081b4959f0a0/lesson/e833d232-febe-4a2d-9bd4-ee8729a1f1a2)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.