Upgrade Kubernetes Cluster on CentOs
Table of contents
No headings in the article.
In this article, I will demonstrate how to upgrade a Kubernetes cluster on CentOS and explore what happens when attempting to update the Kubernetes version by two versions higher at once.
Prerequisites:
A functioning Kubernetes cluster.
A user with sudo or root privileges.
Steps to update Kubernetes version by two versions higher at once:
- Check the current Kubernetes version by executing the following command:
kubectl get nodes
This will display the versions of all nodes, and let's assume our current version is 1.25.0.
As we can see our current version is 1.25.0
- Verify the latest Kubernetes version available by running:
yum list --showduplicates kubeadm --disableexcludes=kubernetes
Or use "kubent" to verify the supported latest versions and dependencies required for the upgrade.
- Attempt to install the latest Kubeadm version 1.27.2 with the following command:
sudo yum install -y kubeadm-1.27.2-0 --disableexcludes=kubernetes
- Check the installed kubeadm version to ensure it is now 1.27.2:
kubeadm version -o json
- Verify the upgrade plan to see the changes required:
kubeadm upgrade plan
At this point, you might encounter a FATAL error stating that to update the cluster from version 1.25.0 to 1.27.2, the control plane version should be equal to or higher than 1.26.0, which is not the case in our current setup.
- To resolve the error, downgrade the kubeadm version to 1.26.5:
yum downgrade -y kubeadm-1.26.5 --disableexcludes=kubernetes
- Verify the upgrade plan again:
kubeadm upgrade plan
- Now that the upgrade plan is feasible, proceed to upgrade the Master node to version 1.26.5:
kubeadm upgrade apply v1.26.5
- Mark the node as unscheduled and exclude workloads:
kubectl drain master-node --ignore-daemonsets
- Update kubelet and kubectl:
yum install -y kubelet-1.26.5-0 kubectl-1.26.5-0 --disableexcludes=kubernetes
- Restart the kubelet service:
sudo systemctl daemon-reload && sudo systemctl restart kubelet
- Check the status of the node:
kubectl get node
At this point, the master node should have a new version of 1.26.5 but may still be disabled. To bring it back online, execute the following command:
kubectl uncordon master-node
Reverify the status of nodes
- Proceed to upgrade the worker node:
Mark the worker node as unscheduled and exclude workloads:
kubectl drain worker-node-1 --ignore-daemonsets
- Update the kubeadm version on the worker node:
yum install -y kubeadm-1.26.5-0 --disableexcludes=kubernetes
- Verify and apply the kubelet configuration update:
sudo kubeadm upgrade node
- Install the new version of kubelet and kubectl:
yum install -y kubelet-1.26.5-0 kubectl-1.26.5-0 --disableexcludes=kubernetes
- Restart the kubelet service:
sudo systemctl daemon-reload && sudo systemctl restart kubelet
- Bring the worker node back online:
kubectl uncordon worker-node-1
- Repeat these steps for other worker nodes if applicable.
In conclusion, we have successfully updated the Kubernetes cluster on CentOS, and we have learned how to handle the scenario when attempting to upgrade Kubernetes by two versions higher at once. To update to the latest version, simply repeat these steps accordingly.