Blog

Upgrading a Kubernetes Cluster Using Kubeadm

Picture of Boyan Kirov
Boyan Kirov
DevOps & Cloud Engineer
02.02.2024
Reading time: 2 mins.
Last Updated: 25.07.2024

Table of Contents

Note: The following example demonstrates upgrading a Kubernetes cluster from version 1.23 to 1.24. Replace the version numbers according to your specific setup.

To ensure a seamless upgrade, it’s crucial to follow these steps in order:

  1. Upgrade the Control Plane node.
  2. Upgrade Worker Nodes.

Additionally, upgrade the following components on both the control plane and worker nodes:

  • Kubeadm
  • Kubelet
  • Kubectl

Before commencing the upgrade process, be sure to identify the cluster and node names. Execute the following command to retrieve the node names:

kubectl get nodes

Upgrade the Control Plane (Master Node)

Step 1: Check the existing Kubeadm version

Log in to the control plane and check the existing version using the following command:

kubeadm version -o json

Step 2: Decide on the upgrade version

Obtain a list of available Kubeadm versions:

sudo apt update
sudo apt-cache madison kubeadm | tac

Alternatively, run a kubeadm upgrade plan for upgrade suggestions:

sudo kubeadm upgrade plan

Step 3: Unhold kubeadm and Install the required version

Unhold kubeadm and install the desired version:

sudo apt-mark unhold kubeadm && \
sudo apt-get update && sudo apt-get install -y kubeadm=1.24.6-00 && \
sudo apt-mark hold kubeadm

Step 4: Apply Kubeadm upgrade

Apply the upgrade:

sudo kubeadm upgrade node

Step 5: Evict all workloads from the control plane

To apply the upgrade, evict all workloads except daemonsets:

kubectl drain master-node --ignore-daemonsets

If using local storage, include –delete-local-data:

sudo kubectl drain master-node --ignore-daemonsets --delete-local-data

Step 6: Upgrade Kubelet and Kubectl

Unhold and upgrade kubectl and kubelet:

sudo apt-mark unhold kubelet kubectl && \

sudo apt-get update && sudo apt-get install -y kubelet=1.24.6-00 kubectl=1.24.6-00 && \

sudo apt-mark hold kubelet kubectl\

Restart the services:

sudo systemctl daemon-reload
sudo systemctl restart kubelet

Step 7: Uncordon the Node and Verify the Node Status

Uncordon the control plane node:

kubectl uncordon master-node

Verify the node status and version:

kubectl get nodes

Upgrade Worker Nodes

Step 1: Unhold Kubeadm and Install Required Version

Install the required version of Kubeadm on worker nodes:

sudo apt-mark unhold kubeadm && \
sudo apt-get update && sudo apt-get install -y kubeadm=1.24.6-00 && \
sudo apt-mark hold kubeadm

Step 2: Upgrade Kubeadm

Run the following command on each worker node:

sudo kubeadm upgrade node

Step 3: Drain the Node

Evict all pods on the worker node by draining it:

kubectl drain worker-node01 --ignore-daemonsets

Step 4: Upgrade Kubelet & Kubectl

Upgrade kubelet and kubectl:

sudo apt-mark unhold kubelet kubectl && \
sudo apt-get update && sudo apt-get install -y kubelet=1.24.6-00 kubectl=1.24.6-00 && \
sudo apt-mark hold kubelet kubectl

Restart kubelet:

sudo systemctl daemon-reload
sudo systemctl restart kubelet

Step 5: Uncordon worker node

kubectl uncordon worker-node01

Verify Cluster Upgrade

Check if the cluster is upgraded and operational

kubectl get nodes

Verify the status of all cluster components:

kubectl get --raw='/readyz?verbose'
curl -k https://localhost:6443/livez?verbose

Also, ensure that all kube-system control node pods are running:

kubectl get po -n kube-system

This completes the Kubernetes cluster upgrade process.

Leave a Reply

Your email address will not be published. Required fields are marked *

More Posts

Learn how to overcome DockerHub rate limits in Kubernetes environments by deploying Harbor as a proxy cache. This guide covers setup steps, image management improvements, and optimizing CI/CD workflows.
Reading
Introduction Integrating Alertmanager with Microsoft Teams enables you to receive alerts directly in Teams channels, facilitating swift collaboration with your team to address issues promptly. This guide will use Prometheus-MSTeams,...
Reading
Get In Touch
ITGix provides you with expert consultancy and tailored DevOps services to accelerate your business growth.
Newsletter for
Tech Experts
Join 12,000+ business leaders and engineers who receive blogs, e-Books, and case studies on emerging technology.