Course contentsShow
← Cloud and Infrastructure
Lesson 1511 of 2,98930. Managed Kubernetes ServicesFree lesson

Node Maintenance and Draining

Safely draining nodes for maintenance using cordon, drain, and scheduling considerations.

Node Maintenance and Draining

What You'll Learn

You'll learn how to safely remove nodes from service for maintenance without disrupting running workloads using Kubernetes' cordon and drain commands.

Why Node Maintenance Matters

In managed Kubernetes environments (EKS, GKE, AKS), nodes occasionally need maintenance—OS patches, kernel upgrades, hardware fixes, or node pool migrations. Simply shutting down a node would terminate pods abruptly, potentially causing service disruptions.

Think of it like an airport runway: you don't just close it mid-flight. You first redirect incoming planes (cordon), wait for current landings to complete (drain), then perform maintenance.

The Three-Step Dance

1. Cordon: Mark as Unschedulable

kubectl cordon <node-name> marks a node as unschedulable. New pods won't land here, but existing pods keep running. It's your "closed for new business" sign.

2. Drain: Evict Existing Pods

kubectl drain <node-name> does the heavy lifting:

  • Cordons the node automatically
  • Evicts all pods gracefully (respecting PodDisruptionBudgets)
  • Waits for pods to terminate cleanly
  • Allows pods to be rescheduled on healthy nodes

Common flags:

  • --ignore-daemonsets: Required since DaemonSet pods can't be evicted
  • --delete-emptydir-data: Allows eviction of pods using emptyDir volumes
  • --grace-period: Controls termination grace time

3. Uncordon: Return to Service

After maintenance, kubectl uncordon <node-name> re-enables scheduling. The node rejoins the healthy pool.

Scheduling Considerations

Drain respects PodDisruptionBudgets (PDBs), ensuring minimum replicas stay available during voluntary disruptions. If a PDB blocks eviction, drain waits or fails, protecting your application's availability guarantees.

Key Takeaway: Node maintenance requires cordoning to prevent new pods, draining to safely evict existing workloads while respecting PodDisruptionBudgets, and uncordoning to restore the node—ensuring zero-downtime operations during infrastructure changes.