Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Prepare a Kubernetes cluster maintenance

By updated

Improve this page

Logo Kubernetes

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

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.

StepCommandWhat happens
1. Block schedulingkubectl cordon <node>The node is marked SchedulingDisabled, no new Pod will be scheduled on it
2. Evacuate the Podskubectl 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 servicekubectl 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.

Terminal window
kubectl cordon <node-name>

Check:

Terminal window
kubectl get nodes
NAME STATUS ROLES AGE VERSION
ks-cp1 Ready control-plane 42h v1.37.0
ks-worker1 Ready,SchedulingDisabled <none> 42h v1.37.0
ks-worker2 Ready <none> 42h v1.37.0

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

Terminal window
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/v1
kind: PodDisruptionBudget
metadata:
name: my-app-pdb
namespace: default
spec:
minAvailable: 2
selector:
matchLabels:
app: my-app

The two main options:

FieldMeaningExample
minAvailableMinimum number (or %) of Pods that must remain available2 or "50%"
maxUnavailableMaximum number (or %) of Pods that can be unavailable1 or "25%"

Check the existing PDBs

Terminal window
kubectl get pdb -A
NAMESPACE NAME MIN AVAILABLE MAX UNAVAILABLE ALLOWED DISRUPTIONS AGE
default my-app-pdb 2 N/A 1 5m

The 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-app

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

Terminal window
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data --disable-eviction

This 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:

  1. cordon the node (if not already done)
  2. 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.

Terminal window
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data

The two most common options:

OptionWhy
--ignore-daemonsetsDaemonSet Pods cannot be moved (by definition they exist on every node). Without this flag, drain refuses to continue.
--delete-emptydir-dataAllows 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.

OptionUsage
--timeout=300sMaximum wait time (default: infinite)
--grace-period=30Graceful termination period per Pod
--forceDeletes Pods without a controller (orphans)
--dry-run=clientSimulates the drain without executing anything
--pod-selector=app=XDrains only the Pods matching the selector

Simulate the drain before running it

Always start with a dry run to see what will be affected:

Terminal window
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data --dry-run=client

This command lists the Pods that would be evacuated without changing anything.

Run the drain

Terminal window
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data

Expected result:

node/ks-worker1 cordoned
evicting pod default/my-app-xyz-abc
evicting pod kube-system/coredns-5d78c9869d-abc
pod/my-app-xyz-abc evicted
pod/coredns-5d78c9869d-abc evicted
node/ks-worker1 drained

Kubernetes 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:

Terminal window
kubectl get pods -A -o wide | grep -v Running

If 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:

Terminal window
kubectl uncordon <node-name>

Check:

Terminal window
kubectl get nodes

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

Terminal window
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:

  1. Check the initial state of the cluster

    Terminal window
    kubectl get nodes
    kubectl get pods -A -o wide --field-selector spec.nodeName=ks-worker1

    Note the Pods present on the node so you can check afterwards that they have been rescheduled.

  2. Check the existing PDBs

    Terminal window
    kubectl get pdb -A

    If ALLOWED DISRUPTIONS is 0 for an application, the drain will be blocked. Make sure the replicas are sufficient.

  3. Simulate the drain

    Terminal window
    kubectl drain ks-worker1 --ignore-daemonsets --delete-emptydir-data --dry-run=client

    Check 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 --force that accepts this.

  4. Run the drain

    Terminal window
    kubectl drain ks-worker1 --ignore-daemonsets --delete-emptydir-data

    Wait until all the Pods are evicted. If the drain blocks, check the PDBs and the resources on the other nodes.

  5. Check that the Pods are rescheduled

    Terminal window
    kubectl get pods -A -o wide | grep -v Running

    All the Pods must be Running on other nodes (except those that are still starting).

  6. Work on the node

    Carry out the planned maintenance (reboot, update, repair).

  7. Put the node back in service

    Terminal window
    kubectl uncordon ks-worker1
  8. Check the return to normal

    Terminal window
    kubectl get nodes
    kubectl top nodes

    The node must go back to Ready, without SchedulingDisabled. 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. A rollout restart of 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.

Terminal window
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=120s
done

On 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:

TypeExamplesProtected by PDBs?
Voluntary, through the Eviction APIkubectl drain, autoscaler removing a nodeYes
Voluntary, outside the Eviction APIkubectl delete pod, deleting a Deployment, rolling updateNo, the budget is bypassed
InvoluntaryHardware failure, kernel panic, node disappearing from the networkNo (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.

SymptomLikely causeSolution
drain blocked indefinitely, or global timeout reachedPDB with ALLOWED DISRUPTIONS: 0Check the replicas and the resources on the other nodes
cannot delete Pods that declare no controllerOrphan Pod (no controller)Add --force if the Pod can be lost
cannot delete DaemonSet-managed PodsDaemonSet detectedAdd --ignore-daemonsets
cannot delete Pods with local storagePod with emptyDirAdd --delete-emptydir-data (the data will be lost)
Pods Pending after drainNot enough resources on the other nodesAdd a node or reduce the requests
Node stays SchedulingDisabled after uncordonuncordon not run or failedRun kubectl uncordon <node> again
Pod Pending after evictionlocal PV tied to the drained nodeWait for the node to return (uncordon) or migrate to a network PV
Pod restarted elsewhere but data missinghostPath volume: the directory only exists on the old nodeGo 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 drain uses the Eviction API, which respects PodDisruptionBudgets, and that is what protects your applications; --disable-eviction bypasses this safeguard and is reserved for emergencies
  • --ignore-daemonsets is often necessary, because drain refuses to evacuate DaemonSet Pods. --delete-emptydir-data must only be used if you explicitly accept losing the data stored in emptyDir
  • Always run a --dry-run=client before the real drain to see which Pods will be affected
  • Evicted Pods do not come back to the node automatically after uncordon: a kubectl rollout restart recreates the Pods and rebalances
  • A PDB with minAvailable: 1 on 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 Ready before 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

7 questions
5 min
80% to pass

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