paint-brush
Upgrade Kubernetes Cluster on CentOsby@vladislavbilay
2,536 reads
2,536 reads

Upgrade Kubernetes Cluster on CentOs

by Vladislav BilayJune 8th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

This article cover Kubernetes version update and what will happen and how to resolve when we decided to update on a two versions up at once.
featured image - Upgrade Kubernetes Cluster on CentOs
Vladislav Bilay HackerNoon profile picture

In this article, I will show you how we can upgrade the Kubernetes Cluster version on CentOS and after that check status of our nodes. We will also consider what happens when we update the version, not one up, but two versions higher at once.


Kubernetes allow update only on one version at once.

Prerequisites:

  • Kubernetes cluster.
  • User with sudo or root privileges.

Try to update the Kubernetes version on two versions higher at once:

Master Node:

In this step, we will review what will happen when we decide to update the Kubernetes version on two versions higher at once and how can we resolve it.


To check the current Kubernetes version execute the following command

kubectl get nodes


As we can see our current version is 1.25.0


Let’s check the latest Kubernetes version.

For that execute the following command.

yum list --showduplicates kubeadm --disableexcludes=kubernetes

Let’s try to install the latest kubeadm version 1.27.2.

For that, we need to execute the following command.

sudo yum install -y kubeadm-1.27.2-0 --disableexcludes=kubernetes


Our kubeadm 1.27.2 was successfully installed and we can check it by executing the following command:

kubeadm version -o json

Now our kubeadm has a 1.27.2 version.

Let’s try to verify the upgrade plan. For that, we need to execute:

kubeadm upgrade plan

After executing this command we see a FATAL error which says that for updating the cluster from 1.25.0 to the 1.27.2 version, we should have a control plane version equal to or higher than 1.26.0, but our current version 1.25.0.


To fix this error we need to downgrade the kubeadm version to 1.26.5 and continue upgrading.

Execute the following command:

yum downgrade -y kubeadm-1.26.5 --disableexcludes=kubernetes


As we can see kubeadm version was successfully downgraded to 1.26.5. And we can continue upgrading our cluster version.

Upgrade Master node

Let’s verify the upgrade plan:

kubeadm upgrade plan


We verified the upgrade plan and now we can upgrade our version to 1.26.5

For that, we need to execute the following command:

kubeadm upgrade apply v1.26.5


It may take several minutes and after that, you will see a successful message that our cluster updated and we can proceed to update kubectl and kubelet.

First of all, we need to mark the node as unscheduled and exclude workloads.

To do that, execute the following command:

kubectl drain master-node --ignore-daemonsets

After that, we can update kubelet and kubectl.

yum install -y kubelet-1.26.5-0 kubectl-1.26.5-0 --disableexcludes=kubernetes

After command execution, we will see that kubectl and kubelet are successfully updated.

In the next step, we need to restart the kubelet service.

sudo systemctl daemon-reload && sudo systemctl restart kubelet


And check the node status

kubectl get node

As we can see master-node has a new version of 1.26.5 but have disabled status and we need to bring it back online.


For that execute the following command:

kubectl uncordon master-node

And re-check status

Upgrade Worker node

After upgrading the master node we need to upgrade the worker node. Please, update only one worker node at a time.


First of all, we need to mark the node as unscheduled and exclude workloads.


For that execute the following command on the Master node:


Note: change “worker-node-1” to your name of the node.

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

After disabling worker-node-1 we can update our worker-node


For that, we need to update the kubeadm version


Execute the following command on worker-node-1

yum install -y kubeadm-1.26.5-0 --disableexcludes=kubernetes

The Kubeadm version was successfully updated and we can verify the upgrade kubelet configuration.

sudo kubeadm upgrade node

After that, we can install a new version of kubelet and kubectl.

yum install -y kubelet-1.26.5-0 kubectl-1.26.5-0 --disableexcludes=kubernetes

After command execution, we will see that kubelet and kubectl are updated.

To apply the new version we need to restart the kubelet service.

sudo systemctl daemon-reload && sudo systemctl restart kubelet


After that, we need to bring back online our worker node:


For that execute the following command on the Master node:

kubectl uncordon worker-node-1

And check the status

That’s it, our worker node successfully upgraded.

Repeat these steps for your other worker nodes.


Conclusion: In this article, we successfully updated the Kubernetes cluster on CentOS and observed the situation when we try to update the Kubernetes version on two versions up.

Repeat all steps to update the Kubernetes version to the current latest version.