Upgrading a Kubernetes (K8s) Cluster Using Kubectl on Linux

May 2, 2025

Introduction

Kubernetes (K8s) is an open-source container orchestration platform that facilitates the management, deployment, and scaling of containerised applications. To maintain security, performance, and access to the latest features, upgrading a Kubernetes cluster is essential. This essay outlines the process of upgrading a Kubernetes cluster using kubectl on a Linux system, covering pre-upgrade checks, the upgrade process, and post-upgrade validation.

Prerequisites

Before upgrading a Kubernetes cluster, ensure the following prerequisites are met:

Backup Your Cluster: Take a snapshot of etcd (if applicable) and back up application manifests.

Check Current Version: Run kubectl version --short to determine the current Kubernetes version.

Review Kubernetes Release Notes: Check the official Kubernetes documentation for breaking changes and deprecations.

Upgrade kubectl: Ensure kubectl is updated to match the desired Kubernetes version:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/

Verify Cluster Status: Check the health of nodes and pods using:

kubectl get nodes

kubectl get pods -A

Upgrading the Kubernetes Cluster

The upgrade process involves upgrading the control plane components and then updating the worker nodes.

Step 1: Upgrade the Control Plane

Drain the Control Plane Node (if applicable):

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

Upgrade kubeadm:

sudo apt update && sudo apt install -y kubeadm=<desired-version>

Verify Upgrade Plan:

kubeadm upgrade plan

Execute the Upgrade:

sudo kubeadm upgrade apply <desired-version>

Uncordon the Control Plane Node:

kubectl uncordon <control-plane-node>

Step 2: Upgrade the Worker Nodes

Drain a Worker Node:

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

Upgrade kubeadm on the Worker Node:

sudo apt update && sudo apt install -y kubeadm=<desired-version>

sudo kubeadm upgrade node

Upgrade kubelet and kubectl on the Worker Node:

sudo apt install -y kubelet=<desired-version> kubectl=<desired-version>

sudo systemctl restart kubelet

Uncordon the Worker Node:

kubectl uncordon <worker-node>

Repeat the Above Steps for Each Worker Node.

Post-Upgrade Validation

After completing the upgrade, perform the following checks:

Verify Kubernetes Version:

kubectl version --short

Check Node Status:

kubectl get nodes

Inspect Pod Health:

kubectl get pods -A

Check Cluster Functionality:

Deploy a test application and ensure it runs as expected.

Monitor logs using kubectl logs.

Conclusion

Upgrading a Kubernetes cluster using kubectl on Linux is a critical maintenance task that ensures security, stability, and new features. By following a systematic approach—preparing adequately, upgrading the control plane, updating worker nodes, and validating the upgrade—the cluster can be kept operational and efficient with minimal downtime. Regular upgrades and adherence to best practices help maintain a robust and secure Kubernetes environment.