Overview:
Testbed scheme:
The overall steps to upgrade Kubernetes cluster are:
- Upgrade all nodes from v1.23.0 --> v1.24.1 To see the latest
kubeadm
releases go to https://kubernetes.io/releases/ - Upgrade Kubernetes control plane
- Upgrade worker nodes
Kubernetes control plane upgrade (control node):
- To upgrade the control node first we need to drain the node:
kubectl drain [node_name] --ignore-daemonsets
- Upgrade the kubeadm (v1.23.0 --> v1.24.1):
sudo apt-get update && \ sudo apt-get install -y --allow-change-held-packages kubeadm=1.24.1-00
- Check the
kubeadm
version:kubeadm version
- To update the Kubernetes control plane internal components use:
You should see the following message:sudo kubeadm upgrade plan v1.24.1
- Now apply the upgrade:
You should see the following message:sudo kubeadm upgrade apply v1.24.1
- Upgrade
kubelet
andkubectl
packages:sudo apt-get update && \ sudo apt-get install -y --allow-change-held-packages kubelet=1.24.1-00 kubectl=1.24.1-00
- Reload the daemon:
sudo systemctl daemon-reload
- Restart the kubelet:
sudo systemctl restart kubelet
- After an upgrade made you can now uncordon the node and back the workload to the node again:
kubectl uncordon [control_node_name]
- Check the upgrade with the following command:
You now should see that control node is upgraded to version 1.24.1:kubectl get nodes
Worker nodes upgrade :
- Now drain the worker node (control node):
ATTENTION:kubectl drain [worker_node_name] --ignore-daemonsets --force
--force
flag is dangerous as it will evict all standalone pods not controlled by Kubernetes controller objects - Now log into your drained worker node and upgrade the
kubeadm
:sudo apt-get update && \ sudo apt-get install -y --allow-change-held-packages kubeadm=1.24.1-00
- Now upgrade the node:
sudo kubeadm upgrade node
- Upgrade the
kubelet
andkubectl
packages:sudo apt-get update && \ sudo apt-get install -y --allow-change-held-packages kubelet=1.24.1-00 kubectl=1.24.1-00
- Reload the daemon:
sudo systemctl daemon-reload
- Restart the kubelet:
sudo systemctl restart kubelet
- Now go back to the control node and uncordon the worker node:
kubectl uncordon [worker_node_name]
- Check if worker node is upgraded:
You should see the following:kubectl get nodes
- Repeat the same process for the rest of worker nodes
Notes:
- Node draining is the mechanism that allows users to gracefully move all containers from one node to the other ones.
- A DaemonSet ensures that all eligible nodes run a copy of a Pod. Normally, the node that a Pod runs on is selected by the Kubernetes scheduler. However, DaemonSet pods are created and scheduled by the DaemonSet controller instead.
--allow-change-held-packages
- overwrites the hold status fromkubeadm
package. Hold status prevents any upgrades of the packagesystemctl
is a Linux command-line utility used to control and manage systemd and services. You can think of Systemctl as a control interface for Systemd init service, allowing you to communicate with systemd and perform operations. Systemctl is a successor of Init.