Upgrade Kubernetes Cluster on CentOs

Nimesh PanchalNimesh Panchal
3 min read

Table of contents

Kubernetes Upgrade: The Definitive Guide to Do-It-Yourself

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:

  1. A functioning Kubernetes cluster.

  2. A user with sudo or root privileges.

Steps to update Kubernetes version by two versions higher at once:

  1. 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.

image

As we can see our current version is 1.25.0

  1. 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.

image

  1. 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

image

  1. Check the installed kubeadm version to ensure it is now 1.27.2:
kubeadm version -o json

image

  1. Verify the upgrade plan to see the changes required:
kubeadm upgrade plan

image

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.

  1. To resolve the error, downgrade the kubeadm version to 1.26.5:
yum downgrade -y kubeadm-1.26.5 --disableexcludes=kubernetes

image

  1. Verify the upgrade plan again:
kubeadm upgrade plan

image

  1. Now that the upgrade plan is feasible, proceed to upgrade the Master node to version 1.26.5:
kubeadm upgrade apply v1.26.5

image

  1. Mark the node as unscheduled and exclude workloads:
kubectl drain master-node --ignore-daemonsets

image

  1. Update kubelet and kubectl:
yum install -y kubelet-1.26.5-0 kubectl-1.26.5-0 --disableexcludes=kubernetes

image

  1. Restart the kubelet service:
sudo systemctl daemon-reload && sudo systemctl restart kubelet
  1. Check the status of the node:
kubectl get node

image

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

image

Reverify the status of nodes

image

  1. Proceed to upgrade the worker node:

Mark the worker node as unscheduled and exclude workloads:

kubectl drain worker-node-1 --ignore-daemonsets

image

  1. Update the kubeadm version on the worker node:
yum install -y kubeadm-1.26.5-0 --disableexcludes=kubernetes

image

  1. Verify and apply the kubelet configuration update:
sudo kubeadm upgrade node

image

  1. Install the new version of kubelet and kubectl:
yum install -y kubelet-1.26.5-0 kubectl-1.26.5-0 --disableexcludes=kubernetes

image

  1. Restart the kubelet service:
sudo systemctl daemon-reload && sudo systemctl restart kubelet
  1. Bring the worker node back online:
kubectl uncordon worker-node-1

image

  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.

0
Subscribe to my newsletter

Read articles from Nimesh Panchal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nimesh Panchal
Nimesh Panchal

I am Nimesh Panchal, a highly skilled and experienced professional with expertise in multiple cloud platforms, including AWS, Azure, and GCP. I am also certified in various cloud and virtualisation technologies, such as CKA, AWS, Azure, GPC, VMware, and Nutanix Throughout my career, I have demonstrated a strong passion for cloud computing and have actively contributed to the success of cloud adoption in diverse industries. My hands-on experience in designing, implementing, and managing cloud-based solutions has allowed me to drive operational efficiency, cost optimization, and scalability for businesses. As a cloud enthusiast, I stay updated with the latest advancements and best practices in the cloud domain. My commitment to continuous learning has enabled me to effectively leverage cloud technologies and deliver impactful solutions to complex challenges. Apart from my cloud expertise, I also possess a solid foundation in networking, virtualization, and data center technologies, making me a well-rounded IT professional. I take pride in collaborating with cross-functional teams and providing leadership in cloud migration, infrastructure design, and cloud security initiatives. My problem-solving skills, coupled with my ability to communicate technical concepts to non-technical stakeholders, have been instrumental in fostering seamless collaboration and driving successful cloud projects.