Question Format
Given an existing Kubernetes cluster running version 1.26.0, upgrade the master node and worker node to version 1.27.0.
Be sure to drain the master and worker node before upgrading it and uncordon it after the upgrade
Introduction
Upgrading a Kubernetes cluster ensures security, stability, and access to the latest features. This guide explains how to upgrade both the master and worker nodes from version 1.31.0 to 1.32.0, including draining nodes before upgrading and uncordoning them afterward.
Prerequisites
Ensure you have:
- Access to the Kubernetes cluster with administrative privileges.
- A working kubectl and kubeadm installation.
- Backup of etcd and cluster state.
Step 1: Drain the Master Node
Before upgrading the master node, drain it to prevent scheduling new workloads.
kubectl drain <master-node-name> --ignore-daemonsets --delete-emptydir-data
Step 2: Upgrade the Master Node
SSH into the master node:
- ssh user@master-node
Update kubeadm:
- sudo apt update && sudo apt install -y kubeadm=1.32.0-00
Now, you should check if upgrade is available, you'll see details about upgrade and plan with this command
sudo kubeadm upgrade plan
( Remember to use this command frequently before applying any upgrade, as it is safe to use and you'll get the full picture of what's about to happen.
Initiate the upgrade:
- sudo kubeadm upgrade apply v1.32.0
Update kubelet and kubectl:
- sudo apt install -y kubelet=1.32.0-00 kubectl=1.32.0-00 sudo systemctl restart kubelet
Uncordon the master node:
- kubectl uncordon <master-node-name>
Step 3: Upgrade Worker Nodes
Drain a worker node:
- kubectl drain <worker-node-name> --ignore-daemonsets --delete-emptydir-data
SSH into the worker node:
- ssh user@worker-node
Update kubeadm:
- sudo apt update && sudo apt install -y kubeadm=1.32.0-00
Upgrade the node:
- sudo kubeadm upgrade node
Update kubelet and restart:
- sudo apt install -y kubelet=1.32.0-00 sudo systemctl restart kubelet
Uncordon the worker node:
- kubectl uncordon <worker-node-name>
Step 4: Verify the Upgrade
Check if all nodes are running the upgraded version:
kubectl get nodes