Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 135Kubernetes · Operations

How to drain a node for maintenance

A Kubernetes node needs a kernel patch, a reboot or a hardware fix. Draining it moves its Pods to other nodes in a controlled way, respecting the apps' PodDisruptionBudgets, so users notice nothing. This how-to cordons and drains a node, handles the usual blockers (DaemonSets, local data, PDBs), does the maintenance, and brings the node back.

  • 5 Lessen
  • 3 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

135.1

The quick answer

kubectl cordon worker2
kubectl drain worker2 --ignore-daemonsets --delete-emptydir-data --timeout=10m
systemctl reboot
kubectl uncordon worker2
kubectl get nodes

cordon = no new Pods here; drain = cordon + evict the running Pods.

135.2

Step by step

  1. Before you start: enough free capacity on the other nodes for the moved Pods, and apps with 2+ replicas (a single-replica app has a short outage).
kubectl get pods -A -o wide --field-selector spec.nodeName=worker2
kubectl get pdb -A
  1. Drain (quick answer). The options:
OptionWhy
--ignore-daemonsetsDaemonSet Pods (CNI, log agents) stay — they belong on every node.
--delete-emptydir-dataPods with emptyDir volumes may be moved (that temp data is lost).
--timeout=10mDo not wait forever.
--pod-selectorDrain only some Pods.
  1. PodDisruptionBudgets — drain waits while evicting a Pod would break a PDB (for example minAvailable: 2 with only 2 ready). You see repeated messages like Cannot evict pod as it would violate the pod's disruption budget. Wait for replacement Pods, or scale up first.
  2. Do the maintenance — patch, reboot, hardware. Then check the node is Ready:
kubectl get node worker2
NAME      STATUS                     ROLES    AGE   VERSION
worker2   Ready,SchedulingDisabled   <none>   212d  v1.33.1
  1. Uncordon — the node accepts Pods again. Existing Pods are not moved back automatically; new Pods and later rollouts will use it.
  2. Many nodes — one by one, waiting until all Pods are Running again before the next. Managed clusters (EKS/AKS/GKE) do the same for node-pool upgrades.

135.3

Check that it worked

After uncordon: the node is Ready (no SchedulingDisabled), all Pods in the cluster are Running, and no app had errors during the drain.

kubectl get pods -A | grep -vE 'Running|Completed'

135.4

Common problems

ProblemCauseFix
cannot delete DaemonSet-managed PodsDaemonSets can not move.--ignore-daemonsets.
cannot delete Pods with local storageemptyDir volumes.--delete-emptydir-data (the temp data is lost).
cannot delete Pods not managed by a controllerBare Pods (no Deployment).--force deletes them for good — check first.
Drain hangs on a PDBNot enough ready replicas elsewhere.Scale up or wait; fix PDBs that allow 0 disruptions.
Pods stay Pending after the drainNo capacity on the other nodes.Add a node first, or lower requests.
Node stays SchedulingDisabledForgot to uncordon.kubectl uncordon NODE.

135.5

Go further

1What is the difference between cordon and drain?

Cordon only stops new Pods on the node; drain also evicts the running Pods.

2Why does a drain sometimes wait for a long time?

A PodDisruptionBudget would be broken; drain waits until enough replicas are ready elsewhere.

Alle commando's in dit hoofdstuk