In this article, we will look how we can upgrade a Kubernetes cluster using kubeadm
Prerequisites
We need a working Kubernetes cluster created using kubeadm
-
If you haven’t created the cluster, please check my previous article below
This will guide you to create a Kubernetes v1.27.0 cluster
Steps
Control Plane
- Verify the version of our cluster by executing the below command in the [control-plane] instance
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
control-plane Ready control-plane 7m5s v1.27.0
node-1 Ready <none> 91s v1.27.0
node-2 Ready <none> 17s v1.27.0
- Update the package index and find the latest kubeadm patch available in the repository
$ sudo apt update
$ sudo apt-cache madison kubeadm
- Unhold the kubeadm package for upgrading
$ sudo apt-cache unhold kubeadm
- Upgrade the kubeadm package to version v1.27.1 and hold the package from automatic upgrading
$ sudo apt install -y kubeadm=1.27.1-00
$ sudo apt-mark hold kubeadm
- Check the upgraded kubeadm version and verify the upgrade plan
$ sudo kubeadm version
$ sudo kubeadm upgrade plan
- Once our plan is verified, we can upgrade the [control-plane] by executing the below command
$ sudo kubeadm upgrade apply v1.27.1
- Prepare the [control-plane] node for maintenance by marking it unschedulable and evicting the workloads
$ kubectl drain control-plane --ignore-daemonsets
- Unhold the kubelet and kubectl packages for an upgrade
$ sudo apt-mark unhold kubelet kubectl
- Upgrade kubelet and kubectl packages to version v1.27.1 and hold the packages from automatic upgrading
$ sudo apt install kubelet=1.27.1-00 kubectl=1.27.1-00
$ sudo apt-mark hold kubelet kubectl
- Restart the kubelet on [control-plane]
$ sudo systemctl daemon-reload
$ sudo systemctl restart kubelet
- Uncordon the [control-plane] for marking it as schedulable
$ kubectl uncordon control-plane
- Verify the nodes, now we can see [control-plane] is upgraded to v1.27.1
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
control-plane Ready control-plane 118m v1.27.1
node-1 Ready <none> 112m v1.27.0
node-2 Ready <none> 111m v1.27.0
Nodes
- Update the package index on [node-1] and unhold the kubeadm package for upgrading
$ sudo apt update
$ sudo apt-mark unhold kubeadm
- Upgrade the kubeadm package to version v1.27.1 on [node-1] and hold the package from automatic upgrading
$ sudo apt install kubeadm=1.27.1-00
$ sudo apt-mark hold kubeadm
- Upgrade the cluster configuration on [node-1] using the below command
$ sudo kubeadm upgrade node
- Prepare the [node-1] for maintenance by marking it unschedulable and evicting the workloads Execute the below drain command on [control-plane]
$ kubectl drain node-1 --ignore-daemonsets --force
- Unhold the kubelet and kubectl packages for upgrade
$ sudo apt-mark unhold kubelet kubectl
- Upgrade kubelet and kubectl packages to version v1.27.1 and hold the packages from automatic upgrading
$ sudo apt install kubelet=1.27.1-00 kubectl=1.27.1-00
$ sudo apt-mark hold kubelet kubectl
- Restart the kubelet on [node-1]
$ sudo systemctl daemon-reload
$ sudo systemctl restart kubelet
- Uncordon the [node-1] for marking it as schedulable Execute the below uncordon command on [control-plane]
$ kubectl uncordon node-1
Repeat the above steps for [node-2] also
Now our cluster is fully upgraded to v1.27.1
Verify the same by executing the below command on [control-plane]
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
control-plane Ready control-plane 136m v1.27.1
node-1 Ready <none> 131m v1.27.1
node-2 Ready <none> 129m v1.27.1
Reference
https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/
https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/upgrading-linux-nodes/
Top comments (0)