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
cordonevicts nothing and why a drain needs--ignore-daemonsetsand--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.
-
Check the initial state,
kubectl get nodesandkubectl get pods -Ato confirm that the cluster is healthy before you intervene. -
Cordon the node,
kubectl cordon <node>marks the node as unschedulable: new pods will no longer be placed on it. -
Drain the pods,
kubectl drain <node> --ignore-daemonsets --delete-emptydir-dataevicts 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-dataoption confirms that you accept losing theemptyDirdata, erased when the pod is evicted. -
Intervene, OS maintenance, disk replacement, component update, reboot.
-
Uncordon,
kubectl uncordon <node>makes the node eligible for scheduling again once the maintenance is over. -
Verify,
kubectl describe node <node>to confirm the return to theReadystate.
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.
Key takeaways
- An object modified live with
kubectl editorkubectl patchmust be carried over to the versioned manifest, otherwise the nextkubectl applyerases the fix - A
cordonevicts nothing: it only prevents new pods from arriving, it iskubectl drainthat 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-dataoption: check that this data is disposable or persisted elsewhere - A PodDisruptionBudget that is too strict can block a drain indefinitely, for example
minAvailable: 1on a single-replica Deployment - The version skew policy has no single rule:
kubeletandkube-proxytolerate up to 3 minor versions behindkube-apiserver, the controller-manager and the scheduler only 1, andkubectlstays within 1 minor version of the API, ahead or behind - Upgrade in kubeadm order:
kubeadmon the first control plane, thenkubeadm upgrade apply, thenkubeletandkubectlon that node, and finally the other nodes one by one withkubeadm 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
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: Changing a live resource: kubectl edit, patch and replace
A new full quiz with random questions
Work again only on the questions you missed