Upgrading Kubernetes Cluster

Upgrading Kubernetes Cluster

Introduction

Keeping your Kubernetes cluster up-to-date is crucial for leveraging new features, improving performance, and ensuring security. Upgrading your cluster might seem daunting, but with the right steps, it can be a smooth and straightforward process. In this blog, we'll walk you through upgrading your Kubernetes cluster from one version to another like 1.30.1 to 1.30.2. This guide will cover everything from preparing your environment to verifying the upgrade, ensuring you can confidently manage your Kubernetes infrastructure.

Prerequisites

  • kubectl installed and configured to access your cluster.

  • kubeadm installed on your control plane nodes.

  • Backup of your cluster data and configurations.

Prepare Your Environment

  • Check the health of your cluster:
kubectl get nodes
kubectl get pods --all-namespaces
  • Backup your cluster data and configurations. You can use tools likeetcdsnapshot for backing up etcd data:
ETCDCTL_API=3 etcdctl snapshot save snapshot.db

Determine which version to upgrade to

Find the latest patch release for Kubernetes 1.30 using the OS package manager:

# Find the latest 1.30 version in the list.
# It should look like 1.30.x-*, where x is the latest patch.
sudo apt update
sudo apt-cache madison kubeadm

Upgrade Control Plane Components

Upgrade kubeadm :

  • Upgrade kubeadm package:

      # replace x in 1.30.x-* with the latest patch version
      sudo apt-mark unhold kubeadm && \
      sudo apt-get update && sudo apt-get install -y kubeadm='1.30.x-*' && \
      sudo apt-mark hold kubeadm
    
  • Verify the version of kubeadm:

      kubeadm version
    
  • Verify the upgrade plan:

      sudo kubeadm upgrade plan
    

Drain the Control Plane Node:

  • Minimize disruptions by draining the node:

      kubectl drain <control-plane-node> --ignore-daemonsets
    
  • Choose a version to upgrade to, and run the appropriate command. For example:

      # replace x with the patch version you picked for this upgrade
      sudo kubeadm upgrade apply v1.30.x
    
  • Mark the node for scheduling

      kubectl uncordon <control-plane-node>
    

Manually upgrade your CNI provider plugin.

Your Container Network Interface (CNI) provider may have its own upgrade instructions to follow. Check the addons page to find your CNI provider and see whether additional upgrade steps are required.

  • This step is not required on additional control plane nodes if the CNI provider runs as a DaemonSet.

For the other control plane nodes

Same as the first control plane node but use:

sudo kubeadm upgrade node

instead of:

sudo kubeadm upgrade apply

Also calling kubeadm upgrade plan and upgrading the CNI provider plugin is no longer needed.

Upgrade kubelet and kubectl on Control Plane Node

  • Upgrade the kubelet and kubectl:

      # replace x in 1.30.x-* with the latest patch version
      sudo apt-mark unhold kubelet kubectl && \
      sudo apt-get update && sudo apt-get install -y kubelet='1.30.x-*' kubectl='1.30.x-*' && \
      sudo apt-mark hold kubelet kubectl
    
  • Restart the kubelet:

      sudo systemctl daemon-reload
      sudo systemctl restart kubelet
    

Upgrading the Worker Node

Login to node

  • SSH to the node

      ssh <node_name>
    

Drain the Worker Node:

  • Minimize disruptions by draining the node:

      kubectl drain <worker-node> --ignore-daemonsets
    
  • Choose a version to upgrade to, and run the appropriate command. For example:

      sudo kubeadm upgrade node
    
  • Bring the node back online by marking it schedulable:

      kubectl uncordon <worker-node>
    

Upgrade kubelet and kubectl on Control Plane Node

  • Upgrade the kubelet and kubectl:

      # replace x in 1.30.x-* with the latest patch version
      sudo apt-mark unhold kubelet \
      sudo apt-get update && sudo apt-get install -y kubelet='1.30.x-*' \
      sudo apt-mark hold kubelet
    
  • Restart the kubelet:

      sudo systemctl restart kubelet
    

Repeat the same process for each worker node.

Verify the Upgrade

  • Verify the status of nodes:

      kubectl get nodes
    
  • Verify Cluster Components:

      kubectl get pods --all-namespaces
    
  • Confirm the Upgrade:

      kubectl version
    

Conclusion

  • Upgrading from v1.30.1 to v1.30.2 ensures your Kubernetes cluster remains secure and efficient.

  • Regular upgrades help maintain performance, security, and feature updates.

Additional Resources