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

Maintenance and Changes on a Kubernetes Cluster

By updated

Improve this page

Any intervention on a production Kubernetes cluster is a deliberate change, and the difference between a successful maintenance and an incident comes down to method. This sub-part teaches the two families of changes of an administrator: modifying an object that is already running, and working on a node without cutting the service, through the cordon, drain, intervention, uncordon cycle.

PodDisruptionBudget objects are the safety net of the second family: they guarantee that your interventions respect the availability constraints of the applications, even during an emergency update, the moment when nobody rereads the manifests.

What you will learn

  • Run the cordon, drain, intervention, uncordon cycle on a node
  • List the three checks to run before a drain
  • Explain why a cordon evicts nothing and why a drain needs --ignore-daemonsets and --delete-emptydir-data
  • Place the four lessons of the sub-part: edit a resource, prepare a maintenance, manage nodes, upgrade the cluster

The maintenance workflow

A node maintenance always follows the same six steps, in this order. The cordon closes the node to new Pods without touching the ones running on it; it is the drain that evicts them, and the uncordon that reopens the node once the intervention is over.

  1. Check the initial state, kubectl get nodes and kubectl get pods -A to confirm that the cluster is healthy before you intervene.

  2. Cordon the node, kubectl cordon <node> marks the node as unschedulable: new pods will no longer be placed on it.

  3. Drain the pods, kubectl drain <node> --ignore-daemonsets --delete-emptydir-data evicts the existing pods to other nodes. Without --ignore-daemonsets, the drain refuses to continue as soon as a DaemonSet pod runs on the node, which almost always happens. Evicting that pod would be pointless: its controller would recreate it right away in the same place. The --delete-emptydir-data option confirms that you accept losing the emptyDir data, erased when the pod is evicted.

  4. Intervene, OS maintenance, disk replacement, component update, reboot.

  5. Uncordon, kubectl uncordon <node> makes the node eligible for scheduling again once the maintenance is over.

  6. Verify, kubectl describe node <node> to confirm the return to the Ready state.

In which order should you follow the maintenance lessons?

The four lessons of this sub-part go from the lightest change to the heaviest. The first, edit a resource in production, teaches you to change a live object with kubectl edit, kubectl patch or kubectl replace, and then to carry the change over to the Git repository to avoid drift: it is often the first step of a maintenance, for instance to adjust a number of replicas before emptying a node.

Next comes prepare a maintenance, which takes up the workflow above with PodDisruptionBudgets and the checks before and after: it is the basic procedure behind the last two lessons.

It continues with node management, the day-to-day administration: labels, taints, annotations and replacement of a failed node. The cluster upgrade comes last because it is the heaviest maintenance: it chains one drain per node and requires the version skew policy, the order of the components, the kubeadm upgrade workflow and the post-upgrade checks.

4 guides published

Key takeaways

  • An object modified live with kubectl edit or kubectl patch must be carried over to the versioned manifest, otherwise the next kubectl apply erases the fix
  • A cordon evicts nothing: it only prevents new pods from arriving, it is kubectl drain that empties the node
  • Never work directly on a node without having drained it, the pods could be interrupted abruptly
  • DaemonSets are not evicted by drain, because their pods are tied to their node and cannot be rescheduled elsewhere: use --ignore-daemonsets
  • emptyDir volumes are erased by drain, hence the --delete-emptydir-data option: check that this data is disposable or persisted elsewhere
  • A PodDisruptionBudget that is too strict can block a drain indefinitely, for example minAvailable: 1 on a single-replica Deployment
  • The version skew policy has no single rule: kubelet and kube-proxy tolerate up to 3 minor versions behind kube-apiserver, the controller-manager and the scheduler only 1, and kubectl stays within 1 minor version of the API, ahead or behind
  • Upgrade in kubeadm order: kubeadm on the first control plane, then kubeadm upgrade apply, then kubelet and kubectl on that node, and finally the other nodes one by one with kubeadm upgrade node

Knowledge check

Check that you have the essentials of this introduction. The questions cover only what was just explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% 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