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 --forceCustomize:
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 terminationStep-by-Step Execution Workflow
1Drain the node
Safely cordon and evict workloads:
kubectl drain node-1 --ignore-daemonsets --delete-emptydir-data2Perform 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-1Common 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.
Related Kubernetes & DevOps Recipes
View All RecipesNetworking & Access
How to Port-Forward a Kubernetes Pod or Service to Localhost
port-forwardGuide β
Debug & Inspection
How to Exec into a Kubernetes Pod with an Interactive Bash Shell
execGuide β
Troubleshooting
How to Debug and Fix CrashLoopBackOff Pods in Kubernetes
logsGuide β
Troubleshooting
How to Force Delete a Kubernetes Pod Stuck in Terminating State
deleteGuide β
Deployments & Workloads
How to Restart a Kubernetes Deployment with Zero Downtime
rolloutGuide β
Monitoring & Resources
How to Check CPU and Memory Resource Usage of Pods and Nodes
topGuide β