To work on a Kubernetes node without cutting the service, always follow the
same workflow: cordon, drain, intervention, uncordon. This guide
details each step, explains how PodDisruptionBudgets protect your applications
during the operation, and covers the special cases (DaemonSets, orphan Pods,
local volumes).
What you will learn
- Apply the complete workflow for maintaining a Kubernetes node
- Understand the difference between cordon (block scheduling) and drain (evacuate the Pods)
- Configure a PodDisruptionBudget to protect your applications during a drain
- Handle the special cases: DaemonSets, Pods without a controller, local data (emptyDir)
- Check that the service is restored after the maintenance
- Rebalance the Pods afterwards and chain several nodes one by one
Prerequisites
- A working Kubernetes cluster on 1.37, the version this training teaches
kubectlconfigured with enough rights to manage nodes (cordon, drain, uncordon)- Rights to create PodDisruptionBudgets
- You have followed the guide Check Kubernetes cluster health with 5 commands
- Basic knowledge of Deployments and Services
Why do you need a maintenance workflow?
On a traditional server, you just reboot. On Kubernetes, a node can host dozens of Pods serving production traffic, and an abrupt reboot has three immediate consequences:
- Service outages if the Pods have no replicas on other nodes
- Data loss if the Pods use local volumes (emptyDir)
- Useless alerts in monitoring
The cordon → drain → uncordon workflow solves all three problems by cleanly
evacuating the Pods before the intervention.
Overview of the workflow
There are four steps, always the same, and their order matters: you prevent new Pods from arriving, then you evacuate the ones that are there, then you intervene, then you reopen the node. Skipping the first step means letting the scheduler place new Pods on the node while you are evacuating it.
| Step | Command | What happens |
|---|---|---|
| 1. Block scheduling | kubectl cordon <node> | The node is marked SchedulingDisabled, no new Pod will be scheduled on it |
| 2. Evacuate the Pods | kubectl drain <node> | The Pods are evicted through the Eviction API, respecting the PDBs |
| 3. Intervene | (reboot, update, repair) | The node is empty, you can work on it safely |
| 4. Put back in service | kubectl uncordon <node> | The node loses SchedulingDisabled and accepts new Pods again |
Step 1: block scheduling with cordon
The kubectl cordon command marks the node SchedulingDisabled. The Pods
already there keep running, but the scheduler will not place any new
one on it. DaemonSets are the exception: their Pods ignore this state
and keep running normally on the node.
kubectl cordon <node-name>Check:
kubectl get nodesNAME STATUS ROLES AGE VERSIONks-cp1 Ready control-plane 42h v1.37.0ks-worker1 Ready,SchedulingDisabled <none> 42h v1.37.0ks-worker2 Ready <none> 42h v1.37.0The node ks-worker1 shows SchedulingDisabled in the STATUS column.
Under the hood, cordon sets the node's spec.unschedulable field to
true, and Kubernetes adds the node.kubernetes.io/unschedulable taint
with the NoSchedule effect. A taint is a mark placed on a node that
repels the Pods that do not tolerate it. That explains the exception for
DaemonSets: their Pods tolerate this taint, so they remain eligible.
kubectl get node ks-worker1 -o jsonpath='{.spec.taints}'[{"effect":"NoSchedule","key":"node.kubernetes.io/unschedulable","timeAdded":"2026-10-13T14:14:06Z"}]Understand PodDisruptionBudgets (PDB) before the drain
Before draining a node, check the PodDisruptionBudgets in place. A PDB defines the minimum number of Pods of an application that must remain available during a voluntary disruption, a drain for example.
What is a PDB?
A PDB protects an application by telling Kubernetes: "never remove more
than X Pods at a time". During a kubectl drain, the Eviction API
respects these budgets and blocks the operation if an eviction would
violate the budget.
Example: a Deployment with 3 replicas and a PDB with minAvailable: 2
means the drain can only evacuate one Pod of this application at a time.
The other two must stay available.
Create a PDB
A PDB is declared next to the application it protects, never on the
node: it expresses an availability requirement, not an infrastructure
constraint. The minAvailable and maxUnavailable fields are mutually
exclusive: choose the one that states your need most naturally.
apiVersion: policy/v1kind: PodDisruptionBudgetmetadata: name: my-app-pdb namespace: defaultspec: minAvailable: 2 selector: matchLabels: app: my-appThe two main options:
| Field | Meaning | Example |
|---|---|---|
minAvailable | Minimum number (or %) of Pods that must remain available | 2 or "50%" |
maxUnavailable | Maximum number (or %) of Pods that can be unavailable | 1 or "25%" |
Check the existing PDBs
kubectl get pdb -ANAMESPACE NAME MIN AVAILABLE MAX UNAVAILABLE ALLOWED DISRUPTIONS AGEdefault my-app-pdb 2 N/A 1 5mThe ALLOWED DISRUPTIONS column shows how many Pods can still be
evicted without violating the budget. If it shows 0, the drain will be
blocked for this application.
What to do when a budget blocks the drain?
When ALLOWED DISRUPTIONS is 0, the drain stays blocked until there
are enough available replicas to respect the budget. Check three points:
the Pods have enough resources to be rescheduled elsewhere, other nodes
are available, and no involuntary disruption (the failure of another node)
already counts against the budget.
One case blocks forever, and nothing points it out: an application that is
already broken, in CrashLoopBackOff for example. Its Pods are not Ready,
so they do not count in the budget, and the default IfHealthyBudget policy
still forbids evicting them. The drain waits for a recovery that will never
come. The unhealthyPodEvictionPolicy: AlwaysAllow field, stable and available
without any setting, allows the eviction of Pods that are already unhealthy and
lifts this blockage:
spec: minAvailable: 2 unhealthyPodEvictionPolicy: AlwaysAllow selector: matchLabels: app: my-appA diagnostic detail costs a lot when ignored: the message names the
cause, never the budget. A blocked drain retries every five seconds and
prints it, with or without --timeout:
error when evicting pods/"app-69ccd78fc8-qgtmr" -n "production" (will retry after 5s):Cannot evict pod as it would violate the pod's disruption budget.So you know that a budget is blocking, but not which one: its name
appears in the API response, which kubectl does not display. With
--timeout, the command ends on global timeout reached; without it, it
retries indefinitely. List kubectl get pdb -A before starting the
drain, not after waiting ten minutes.
Bypass a PDB in an emergency: --disable-eviction
When the node must be emptied right now, a machine that is failing for
example, the --disable-eviction option deletes the Pods directly instead
of going through the Eviction API. The budget is then no longer
consulted at all. On a PDB that required 6 available Pods out of 6:
the normal drain stops on global timeout reached, while the same command
with --disable-eviction deletes the two Pods of the node and ends on
node/... drained, even though ALLOWED DISRUPTIONS still shows 0.
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data --disable-evictionThis is exactly the service outage that the budget was meant to prevent: reserve this option for emergencies, never for a planned maintenance.
Step 2: evacuate the Pods with drain
This is the step that actually moves the load, and the only one that can
cause an interruption if it is badly prepared. kubectl drain does not
delete the Pods abruptly: it goes through the Eviction API, the one
that PodDisruptionBudgets can refuse. That is what sets it apart from a
mass kubectl delete pod.
The command combines two actions:
cordonthe node (if not already done)- Evacuate all the Pods through the Eviction API (which respects the PDBs)
Basic command
Two options come up so systematically that they are part of the command.
Without them, drain refuses to start and returns the list of what
is in its way: that is, by the way, a way to discover what the node
hosts.
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-dataThe two most common options:
| Option | Why |
|---|---|
--ignore-daemonsets | DaemonSet Pods cannot be moved (by definition they exist on every node). Without this flag, drain refuses to continue. |
--delete-emptydir-data | Allows deleting Pods that use emptyDir (ephemeral local volumes). Use it only if you accept losing that data. |
Useful options
On a production cluster, always set two of these options.
--dry-run=client shows what would be evacuated without touching
anything, and --timeout avoids waiting forever on a drain that nothing
will unblock.
| Option | Usage |
|---|---|
--timeout=300s | Maximum wait time (default: infinite) |
--grace-period=30 | Graceful termination period per Pod |
--force | Deletes Pods without a controller (orphans) |
--dry-run=client | Simulates the drain without executing anything |
--pod-selector=app=X | Drains only the Pods matching the selector |
Simulate the drain before running it
Always start with a dry run to see what will be affected:
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data --dry-run=clientThis command lists the Pods that would be evacuated without changing anything.
Run the drain
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-dataExpected result:
node/ks-worker1 cordonedevicting pod default/my-app-xyz-abcevicting pod kube-system/coredns-5d78c9869d-abcpod/my-app-xyz-abc evictedpod/coredns-5d78c9869d-abc evictednode/ks-worker1 drainedKubernetes automatically reschedules the evicted Pods on the remaining nodes (if resources allow).
Before draining, make sure the other nodes can take in what this one
hosts. The drain succeeds anyway, since its job is to evict; it is
the evicted Pods that will stay Pending, and you will then have
an outage instead of a maintenance.
Special cases of the drain
Pods without a controller (orphans): if a Pod is not managed by any
Deployment, ReplicaSet, StatefulSet, DaemonSet or Job, drain refuses to
delete it because it will not be recreated. Use --force as a last resort
(the Pod will be permanently deleted).
StatefulSet Pods: beware of a persistent misconception. kubectl drain
evicts all the Pods of the node in parallel, one routine per Pod,
StatefulSet Pods included. Only a PodDisruptionBudget enforces one at a
time: without it, three replicas of a database hosted on the same node leave
together. The controller then recreates them in order, which does not
repair the unavailability suffered in the meantime. Also check that the PVCs
are reachable from the other nodes.
Pods with emptyDir: the data in emptyDir is lost when the Pod is
evicted. If that data matters, back it up before the drain or migrate to a
PersistentVolume.
Pods with storage local to the node (hostPath, local PV): the two
cases do not behave the same way, and hostPath is the more misleading
one. A local PV carries a node affinity: after eviction, the Pod
that claims it stays Pending as long as its node is unavailable. A
hostPath volume, on the other hand, imposes no constraint on the
scheduler: the Pod restarts without error on another node, but finds an empty
or different directory there, so without its data. For these workloads,
plan either a return to the same node after the maintenance, or a migration
to a network PersistentVolume (NFS, Ceph, cloud provider).
Step 3: work on the node
The node is now empty (except for the DaemonSets). You can:
- Reboot the node (
sudo reboot) - Update the system (
apt upgrade,dnf update) - Update the kubelet and the Kubernetes components
- Repair a hardware or disk problem
- Change the configuration of the kubelet
During the intervention, check that the evicted Pods have been rescheduled on the other nodes:
kubectl get pods -A -o wide | grep -v RunningIf some Pods are Pending, the remaining nodes lack resources.
Step 4: put the node back in service with uncordon
After the intervention, put the node back in service:
kubectl uncordon <node-name>Check:
kubectl get nodesThe node must show Ready (without SchedulingDisabled).
An uncordon reopens the node to future placements, it brings nobody
back. The evicted Pods now run elsewhere and will stay there until
their next restart. If the distribution matters to you, what you need is a
rebalancing, not the uncordon.
Rebalance the Pods after uncordon
The scheduler only places a Pod at its creation: for a reopened node to
receive its share, Pods must therefore be recreated. The simplest way is
kubectl rollout restart, which gradually replaces the Pods of a
Deployment while respecting its update strategy.
kubectl rollout restart deployment/<name>On a Deployment of 6 replicas spread over three workers, the distribution
stays at 0/3/3 after the drain then the uncordon of the first one, and goes
back to 2/2/2 after the rollout restart. For an automatic and permanent
rebalancing, the Descheduler project
(kubernetes-sigs/descheduler) periodically evicts badly placed Pods, at the
price of one more component to operate.
Complete practical example
Here is the complete workflow for a maintenance of the node ks-worker1:
-
Check the initial state of the cluster
Terminal window kubectl get nodeskubectl get pods -A -o wide --field-selector spec.nodeName=ks-worker1Note the Pods present on the node so you can check afterwards that they have been rescheduled.
-
Check the existing PDBs
Terminal window kubectl get pdb -AIf
ALLOWED DISRUPTIONSis0for an application, the drain will be blocked. Make sure the replicas are sufficient. -
Simulate the drain
Terminal window kubectl drain ks-worker1 --ignore-daemonsets --delete-emptydir-data --dry-run=clientCheck the list of Pods that will be evicted. If a Pod without a controller appears, decide whether it is acceptable to lose it: nobody will recreate it, and it is
--forcethat accepts this. -
Run the drain
Terminal window kubectl drain ks-worker1 --ignore-daemonsets --delete-emptydir-dataWait until all the Pods are evicted. If the drain blocks, check the PDBs and the resources on the other nodes.
-
Check that the Pods are rescheduled
Terminal window kubectl get pods -A -o wide | grep -v RunningAll the Pods must be
Runningon other nodes (except those that are still starting). -
Work on the node
Carry out the planned maintenance (reboot, update, repair).
-
Put the node back in service
Terminal window kubectl uncordon ks-worker1 -
Check the return to normal
Terminal window kubectl get nodeskubectl top nodesThe node must go back to
Ready, withoutSchedulingDisabled. Its CPU and memory consumption stays low as long as no Pod is created on it: this is normal, evicted Pods do not come back on their own. Arollout restartof the Deployments concerned fills it up again.
Maintain several nodes: one at a time
To patch all the workers, handle them one by one: draining two nodes at
the same time removes twice as much capacity and can bring down all the
replicas of an application at once. The loop below only moves on to the next
node once the previous one is reopened and Ready, thanks to the final
kubectl wait, and the selector !node-role.kubernetes.io/control-plane
leaves out the control plane.
for node in $(kubectl get nodes -l '!node-role.kubernetes.io/control-plane' -o name); do kubectl drain "$node" --ignore-daemonsets --delete-emptydir-data --timeout=300s # work on the node here (update, reboot) kubectl uncordon "$node" kubectl wait --for=condition=Ready "$node" --timeout=120sdoneOn a kind cluster with three workers, the loop chains drained,
uncordoned and then condition met for each of them. The
--timeout=300s matters here: without it, a blocking budget freezes
the whole loop forever.
Voluntary and involuntary disruptions
Kubernetes distinguishes two types of disruptions:
| Type | Examples | Protected by PDBs? |
|---|---|---|
| Voluntary, through the Eviction API | kubectl drain, autoscaler removing a node | Yes |
| Voluntary, outside the Eviction API | kubectl delete pod, deleting a Deployment, rolling update | No, the budget is bypassed |
| Involuntary | Hardware failure, kernel panic, node disappearing from the network | No (but counted in the budget) |
PDBs only protect what goes through the Eviction API, as the second row of
the table shows: a kubectl delete pod bypasses the budget even though it
is voluntary too. A hardware failure, for its part, evicts the Pods
without consulting anything. However, these involuntary disruptions
count in the available budget: a Pod that fails makes
ALLOWED DISRUPTIONS go down, which can block a drain started
afterwards. Hence the value of combining a PDB with enough replicas and
anti-affinity, to spread the Pods across several nodes.
Quick troubleshooting
Most of these symptoms occur during the operation, so at the worst possible moment. It is better to read them in advance than to discover them on a maintenance evening: three of them are fixed by an option that you only had to add.
| Symptom | Likely cause | Solution |
|---|---|---|
drain blocked indefinitely, or global timeout reached | PDB with ALLOWED DISRUPTIONS: 0 | Check the replicas and the resources on the other nodes |
cannot delete Pods that declare no controller | Orphan Pod (no controller) | Add --force if the Pod can be lost |
cannot delete DaemonSet-managed Pods | DaemonSet detected | Add --ignore-daemonsets |
cannot delete Pods with local storage | Pod with emptyDir | Add --delete-emptydir-data (the data will be lost) |
Pods Pending after drain | Not enough resources on the other nodes | Add a node or reduce the requests |
Node stays SchedulingDisabled after uncordon | uncordon not run or failed | Run kubectl uncordon <node> again |
Pod Pending after eviction | local PV tied to the drained node | Wait for the node to return (uncordon) or migrate to a network PV |
| Pod restarted elsewhere but data missing | hostPath volume: the directory only exists on the old node | Go back to the same node or migrate to a network PV |
Hands-on practice
Emptying a node without cutting the service means protecting the application before touching the node. This lab has you create a PodDisruptionBudget, then cordon and drain the worker while respecting that budget and the DaemonSets. The validation checks that the Pods were really recreated elsewhere and that the CNI DaemonSet did not move.
Key takeaways
- The workflow is always the same:
cordon,drain, intervention,uncordon. Never skip the drain to save time kubectl drainuses the Eviction API, which respects PodDisruptionBudgets, and that is what protects your applications;--disable-evictionbypasses this safeguard and is reserved for emergencies--ignore-daemonsetsis often necessary, becausedrainrefuses to evacuate DaemonSet Pods.--delete-emptydir-datamust only be used if you explicitly accept losing the data stored inemptyDir- Always run a
--dry-run=clientbefore the real drain to see which Pods will be affected - Evicted Pods do not come back to the node automatically after
uncordon: akubectl rollout restartrecreates the Pods and rebalances - A PDB with
minAvailable: 1on a Deployment with 1 replica will block the drain indefinitely, so make sure your critical applications have at least 2 replicas - Maintain the nodes one by one, waiting for each to be back
Readybefore moving on to the next
Knowledge check
Seven questions on what really happens during a maintenance: what a
cordon does not do, why a blocked drain does not name the responsible
budget, and what an uncordon does not bring back.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Manage Kubernetes cluster nodes day to day
A new full quiz with random questions
Work again only on the questions you missed