Interview's MateKubernetes
Interview's Mate

Kubernetes

K8s · Workloads · GitOps · Cloud

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Kubernetes topics
Lesson 144/ 160
08. Cluster Administration & Managed Cloud Kubernetes

Node Maintenance Operations (cordon, drain, uncordon)

Safely take nodes out of service with cordon, drain, and uncordon.

Beginnercordon · drain · uncordon3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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-2 and 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

Loading interactive 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.

Verify drain, not only object creation

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.

Key takeaway: cordon is implemented only when this invariant remains observable: 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.

Recover from drain drift

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.

Key takeaway: Accept the trade-off consciously: Maintenance is safer with spare capacity and graceful termination, but DaemonSets, local storage, debug Pods, and emptyDir exceptions require explicit decisions.

How it works, step by step

Step 1 of 4
Platform planner

1. 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.

cordon contract → owned state
Key numbers at this step
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-2 in 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-2 first: 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

Repeatable infrastructure control
Best for: Safely take nodes out of service with cordon, drain, and uncordon. A concrete incident check is 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.

Manual cluster mutation
Best for: Quickly testing the drain assumption with 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.

Managed cloud or platform service
Best for: Teams that need uncordon integrated with guardrails; the evidence path is 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-2 without 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?
Interview tip: Interview sequence: state the invariant, run 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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Zero-Downtime Kubernetes Cluster Upgrades (Control Plane & Worker Nodes)
Next topic
High Availability (HA) Topologies (Stacked vs External etcd)