session

~/chopper

article

Kubernetes Cluster Version Upgrade

If you are performing a version upgrade for your Kubernetes Cluster, this guide walks you through the process step by step with simple explanations.

It also assumes that you are using Linux-based environment. The first thing you need to do is to upgrade your package repository configuration.

Package Repository

A Package repository stores versioned software packages (such as Kubernetes components like kubeadm, kubectl, kubelet) that can be installed on your system. Your system downloads these packages from the repository.

Kubernetes packages contain compiled binaries, configuration files and dependencies required to run Kubernetes components.

apt is a package manager used in Ubuntu and Debian-based distributions. It helps install, update and manage software packages.

Kubeadm

Kubeadm manages the Kubernetes cluster lifecycle. It is used to create your production-grade Kubernetes cluster with a few commands and it also provides a straightforward way to upgrade your cluster.

However, Kubeadm only updates the control plane components.

When you perform a cluster upgrade with kubeadm, kubelet and kubectl are not updated automatically since they are not managed as pods inside the cluster.

  • kubectl is a tool that we use to interact with the Kubernetes API server and runs outside the cluster.
  • kubelet is a systemd service that runs on each node and it manages and deploys pods onto the node by communicating with the API server.

These components are installed by the apt package manager and must be explicitly upgraded.

Upgrade Kubeadm Package

First, update the kubernetes apt repository version in:

/etc/apt/sources.list.d/kubernetes.list

Example:

https://pkgs.k8s.io/core:/stable:/v1.35/deb/

Then, run these commands

sudo apt update (update the available versions of all packages)
sudo apt-cache madison kubeadm (list out those)

You will see the list of available versions from the repository you configured.

Pre-flight check

Check what versions you could upgrade the cluster components with this command.

sudo kubeadm upgrade plan

Drain the node

Before upgrading, drain the node to safely evict workloads. It avoids downtime by rescheduling pods to other nodes.

kubectl drain <node> --ignore-daemonsets --delete-emptydir-data

Apply the Upgrade

To perform cluster upgrade without interrupting users, upgrade the control plane node first, then upgrade each worker node one by one.

sudo kubeadm upgrade apply v1.35.x (the version to upgrade)

For worker nodes, use “upgrade node” command instead of “upgrade apply”

sudo kubeadm upgrade node

Upgrade Kubectl and Kubelet Explicitly

sudo apt-mark unhold kubelet kubectl && \
sudo apt-get update && sudo apt-get install -y kubelet='1.35.x-*' kubectl='1.35.x-*' && \
sudo apt-mark hold kubelet kubectl

unhold -> allows upgrades update & install -> upgrades to the specific version hold -> prevents unintended upgrades

Restart Kubelet service

sudo systemctl daemon-reload
sudo systemctl restart kubelet

Daemon-reload reloads service configuration files. Without reloading those service files, systemctl will re-apply old configuration file for the service even if you updates the package recently. Systemctl will apply latest config file for the service and restarts the kubelet properly.

Verify

If all the processes are successfully completed, verify the version of the cluster node.

kubectl get nodes -o wide

Then, repeats the same steps on the worker nodes. This is how you simply upgrade your Kubernetes cluster.