Node Maintenance Operations (cordon, drain, uncordon)
Safely take nodes out of service with cordon, drain, and uncordon.
In plain words
Cordon closes the loading gate, drain asks current passengers to relocate, and uncordon reopens the platform only after repairs. The simple Kubernetes rule is: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
Think of it like…
Cordon closes the loading gate, drain asks current passengers to relocate, and uncordon reopens the platform only after repairs.
Where you’ve seen it
During a controlled maintenance window, the platform operator runs kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2. Expected evidence: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation. If the run instead shows this symptom, stop and restore the last known state: Cordon does not move running workloads, a stuck PDB can block drain, and force deletion or ignoring all eviction safety can remove the last replica.
Words you’ll hear
- cordon
- For this lesson, cordon is the controlling idea: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
- drain
- drain is the checkpoint; run
kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2and inspect the owner chain. Cordon does not move running workloads, a stuck PDB can block drain, and force deletion or ignoring all eviction safety can remove the last replica. - uncordon
- uncordon is the outcome to preserve; the cost is explicit: Maintenance is safer with spare capacity and graceful termination, but DaemonSets, local storage, debug Pods, and emptyDir exceptions require explicit decisions.
- Verification evidence
- The evidence command is
kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2. It connects the declaration to this behavior: Safely take nodes out of service with cordon, drain, and uncordon.
Visual diagram
Theory & deep dive
How cordon reaches the intended state
Safely take nodes out of service with cordon, drain, and uncordon. Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
The concrete checkpoint is kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2; compare the cordon owner, drain state, and uncordon outcome instead of treating YAML acceptance as proof.
Run kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2 after the change and correlate the result with Events and the owning object. Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
drain: failure boundary and production cost
Cordon does not move running workloads, a stuck PDB can block drain, and force deletion or ignoring all eviction safety can remove the last replica. The prerequisite contract is concrete: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
Maintenance is safer with spare capacity and graceful termination, but DaemonSets, local storage, debug Pods, and emptyDir exceptions require explicit decisions. A safe design limits blast radius, records the last good configuration, and uses kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2 as a deterministic rollback checkpoint.
Capture the current state with kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: Cordon does not move running workloads, a stuck PDB can block drain, and force deletion or ignoring all eviction safety can remove the last replica.
How it works, step by step
Step 1 of 41. Plan the lifecycle boundary
Inventory versions, capacity, state, backups, and ownership in a reversible plan: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
- Goal
- Safely take nodes out of service with cordon, drain, and uncordon.
- Owner
- cordon
When to use it & trade-offs
What it is
Safely take nodes out of service with cordon, drain, and uncordon. Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
Why it matters: Cordon does not move running workloads, a stuck PDB can block drain, and force deletion or ignoring all eviction safety can remove the last replica. The invariant at risk is specific: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation. The quickest fact check before changing the design is kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2.
When to reach for it
- Use cordon to enforce this invariant: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
- Use drain evidence from
kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2in reviews and incident timelines. Safely take nodes out of service with cordon, drain, and uncordon. - Choose the managed cloud or platform service route only when this cost is justified by governance or scale: Maintenance is safer with spare capacity and graceful termination, but DaemonSets, local storage, debug Pods, and emptyDir exceptions require explicit decisions.
When to avoid or be careful
- Avoid assuming cordon is complete after YAML submission; the required behavior is concrete: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
- Avoid treating the next symptom as random; check the owner and state with
kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2first: Cordon does not move running workloads, a stuck PDB can block drain, and force deletion or ignoring all eviction safety can remove the last replica. - Avoid adopting a heavier platform wrapper before measuring its cost: Maintenance is safer with spare capacity and graceful termination, but DaemonSets, local storage, debug Pods, and emptyDir exceptions require explicit decisions.
Native, manual, and managed paths for cordon
kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2.Strengths: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
Watch out: Maintenance is safer with spare capacity and graceful termination, but DaemonSets, local storage, debug Pods, and emptyDir exceptions require explicit decisions. Recovery must also recognize this signal: Cordon does not move running workloads, a stuck PDB can block drain, and force deletion or ignoring all eviction safety can remove the last replica.
kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2; the expected invariant is: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.Strengths: kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2 gives immediate feedback without first building a platform layer.
Watch out: A manual change can hide drift, and unlike cordon, it does not make this symptom self-documenting: Cordon does not move running workloads, a stuck PDB can block drain, and force deletion or ignoring all eviction safety can remove the last replica.
kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2.Strengths: Platform controls can wrap this exact behavior in policy or dashboards: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
Watch out: The added platform ownership buys value at this cost: Maintenance is safer with spare capacity and graceful termination, but DaemonSets, local storage, debug Pods, and emptyDir exceptions require explicit decisions.
Interview signals & numbers to know
When this topic comes up
- Interview anchor: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
- Trace cordon to uncordon through drain; the invariant is: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
- Recognize the symptom: Cordon does not move running workloads, a stuck PDB can block drain, and force deletion or ignoring all eviction safety can remove the last replica.
- Justify the cost: Maintenance is safer with spare capacity and graceful termination, but DaemonSets, local storage, debug Pods, and emptyDir exceptions require explicit decisions.
- Verify with kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2 instead of only inspecting YAML.
Benchmarks & rules of thumb
- 0
- existing Pods are automatically moved by cordon
- 2
- drain exclusions often needed: DaemonSets and reviewed emptyDir Pods
- 1
- node must be healthy enough to schedule after uncordon
Common mistakes & follow-ups
Common interview mistakes
- Debugging only the child object misses the cordon owner contract: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation.
- Ignoring this telltale condition leads to unrelated changes: Cordon does not move running workloads, a stuck PDB can block drain, and force deletion or ignoring all eviction safety can remove the last replica.
- Repeating
kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2without an owner for remediation wastes retry cost. Maintenance is safer with spare capacity and graceful termination, but DaemonSets, local storage, debug Pods, and emptyDir exceptions require explicit decisions.
Likely interviewer follow-ups
- How would API output and runtime evidence prove this behavior: cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation?
- Which owner object, logs, and Events would you inspect for this symptom-Cordon does not move running workloads, a stuck PDB can block drain, and force deletion or ignoring all eviction safety can remove the last replica-?
- At what threshold would this cost become unacceptable: Maintenance is safer with spare capacity and graceful termination, but DaemonSets, local storage, debug Pods, and emptyDir exceptions require explicit decisions?
kubectl cordon worker-2; kubectl drain worker-2 --ignore-daemonsets --delete-emptydir-data; kubectl uncordon worker-2, name the failure, then justify the cost. Invariant: Cordon marks a node unschedulable, drain evicts eligible Pods through the API and honors PDBs, and uncordon restores it to the scheduler after validation. Failure: Cordon does not move running workloads, a stuck PDB can block drain, and force deletion or ignoring all eviction safety can remove the last replica. Cost: Maintenance is safer with spare capacity and graceful termination, but DaemonSets, local storage, debug Pods, and emptyDir exceptions require explicit decisions.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Node Maintenance Operations (cordon, drain, uncordon) with generative AI interview Q&A and hands-on practice.