Kubernetes β€’ Cluster & Nodes

How to Safely Drain a Kubernetes Node for Maintenance

`kubectl drain` cordons the specified node (marking it unschedulable) and evicts running pods respecting PodDisruptionBudgets (PDBs). Evicted pods are rescheduled onto other healthy worker nodes in the cluster.

Safely Drain Node Command
Destructive β€’ Evicts Workloads or Purges State
kubectl drain node-1 --ignore-daemonsets --delete-emptydir-data --force
Customize:
Namespace:
Resource Name:

Flags & Parameter Breakdown

--ignore-daemonsetsSkip DaemonSet-managed pods (monitoring, networking, logging)
--delete-emptydir-dataAllow eviction even if pods use emptyDir ephemeral storage
--grace-period=<sec>Override default grace period for pod termination

Step-by-Step Execution Workflow

1Drain the node

Safely cordon and evict workloads:

kubectl drain node-1 --ignore-daemonsets --delete-emptydir-data
2Perform maintenance

Perform OS upgrades, kernel updates, or hardware replacement.

3Uncordon node after maintenance

Mark the node schedulable again so it can accept new pods:

kubectl uncordon node-1

Common Pitfalls & Troubleshooting Advice

  • If pods are stuck evicting, check if a PodDisruptionBudget (PDB) is preventing minimum available replicas from dropping.
  • Do not forget to run `kubectl uncordon <node>` once maintenance is complete.

Prerequisites & Cluster Access

  • Cluster admin access.
  • Sufficient compute capacity on remaining nodes to absorb workloads.

Frequently Asked Questions About Safely Drain Node

Frequently Asked Questions

Frequently Asked Questions

Everything you need to know regarding specifications, syntax, and security best practices.

`cordon` merely prevents new pods from being scheduled on the node. `drain` cordons the node AND actively evicts all existing pods to other nodes.