Upgrading a Kubernetes Cluster from v1.31.0 to v1.31.4

Chamod Shehanka Perera
4 min readJan 4, 2025

--

Introduction

Upgrading Kubernetes is essential to maintain security, gain new features, and fix bugs. In this guide, we’ll upgrade a Kubernetes cluster from v1.31.0 to v1.31.4 step-by-step. This includes upgrading the control plane, worker nodes, and validating the upgrade. The process applies to clusters managed with kubeadm.

1. Pre-Upgrade Preparation

  1. Backup Your Cluster (Not needed for CKA):
  • Use tools like Velero to back up Kubernetes resources and persistent volumes.
  • Ensure you have a snapshot of your etcd database if it’s a self-managed cluster.
etcdctl snapshot save backup.db

2. Check Current Cluster State:

  • Verify all nodes and pods are in a healthy state before proceeding:
kubectl get nodes kubectl get pods --all-namespaces

3. Verify Installed Kubernetes Version:

  • Check the current versions of the control plane and worker nodes:
kubectl version --short

Output should show v1.31.0.

4. Plan Downtime (Not needed for CKA):

  • Even though Kubernetes upgrades are designed to be non-disruptive, it’s wise to inform stakeholders about potential disruptions during the upgrade process.

2. Plan the Upgrade

Run the kubeadm upgrade plan command to check available versions and ensure your cluster is ready:

kubeadm upgrade plan

This command provides:

  • The current Kubernetes version.
  • Available versions to upgrade.
  • Any pre-check warnings or failures.

If there are compatibility issues with plugins or workloads, resolve them before continuing (Not needed for CKA).

3. Upgrade the Control Plane

  1. Update kubeadm Package: On the control plane node, update kubeadm to the desired version:
sudo apt-get update
sudo apt-get install -y kubeadm=1.31.4-1.1

2. Apply the Upgrade: Execute the upgrade process for the control plane:

sudo kubeadm upgrade apply v1.31.4

During this step:

  • Etcd and API server will be updated.
  • Cluster components like the scheduler and controller manager will be upgraded.
  • Follow prompts carefully and review logs for errors.

This step might take around 5 minutes.

3. Upgrade kubectl, kubelet

sudo apt-get install kubectl=1.31.4-1.1 kubelet=1.31.4-1.1

4. Restart kubelet: After upgrading the control plane, restart the kubelet service:

sudo systemctl restart kubelet

4. Upgrade Worker Nodes

Worker nodes need to match the control plane version to ensure compatibility.

  1. Drain the Node (Optional and not needed for CKA): Safely remove workloads from the node before upgrading
kubectl drain <node-name> --ignore-daemonsets --delete-local-data

This ensures pods running on the node are rescheduled on other nodes.

2. SSH into the Worker Node:

ssh <worker-node>

3. Upgrade kubeadm: Update kubeadm to the same version as the control plane

sudo apt-get update
sudo apt-get install -y kubeadm=1.31.4-1.1

4. Execute the Node Upgrade:
Run the following to align the worker node configuration

sudo kubeadm upgrade node

5. Upgrade kubelet

sudo apt-get install  kubelet=1.31.4-1.1

6. Restart kubelet:

sudo systemctl restart kubelet

7. Uncordon the Node (Not needed for CKA): Make the node schedulable again:

kubectl uncordon <node-name>

8. Repeat for All Worker Nodes:

  • Perform the above steps for each worker node in your cluster.

5. Post-Upgrade Validation

  1. Verify Cluster Health:
    Check that all nodes are in the Ready state:
kubectl get nodes

All nodes should now display v1.31.4

2. Validate Workloads:

kubectl get pods --all-namespaces

6. Optional Steps for CKA Preparation

Use this upgrade process to practice for the Certified Kubernetes Administrator (CKA) exam:

  1. Familiarize yourself with kubeadm upgrade options.
  2. Practice troubleshooting common upgrade issues (e.g., mismatched versions or configuration errors).
  3. Simulate upgrading multiple nodes in a controlled environment.

7. Production Cluster Considerations (Not needed for CKA)

Backup and Monitoring:

  • Use tools like Prometheus and Grafana to monitor resource usage.
  • Back up etcd data before any upgrade.

Staggered Upgrades:

  • Upgrade worker nodes in phases to reduce the impact on workloads.

Test in a Staging Environment:

  • Always test the upgrade on a staging cluster to identify issues before deploying to production.

Conclusion

Upgrading Kubernetes is critical for maintaining a secure and performant cluster. This step-by-step guide ensures a smooth upgrade from v1.31.0 to v1.31.4, minimizing downtime and risk. Whether you’re preparing for the CKA exam or managing a production cluster, understanding the upgrade process is invaluable.

--

--

Chamod Shehanka Perera
Chamod Shehanka Perera

Written by Chamod Shehanka Perera

Software Engineer | GitHub Field Expert | Golang Sri Lanka Lead | GDG Organizer | KCD Sri Lanka Organizer| Beginner Surfer

No responses yet