Question 20: Update Kubernetes

Problem Statement

Solve this question on: ssh cks8930

The cluster is running Kubernetes 1.31.5, update it to 1.32.1.

Requirements:

  • Use apt package manager and kubeadm for this
  • Use ssh cks8930-node1 from cks8930 to connect to the worker node
Use sudo -i to become root which may be required for this question

Solution

Step 1: Check Current Versions

First, let's check the current versions of all nodes:

➜ ssh cks8930

➜ candidate@cks8930:~# k get node
NAME            STATUS   ROLES           AGE   VERSION
cks8930         Ready    control-plane   22h   v1.31.5
cks8930-node1   Ready              22h   v1.31.5
Step 2: Update Control Plane

First, drain the control plane node:

➜ candidate@cks8930:~# k drain cks8930 --ignore-daemonsets
node/cks8930 cordoned
Warning: ignoring DaemonSet-managed Pods: kube-system/kube-proxy-wr9pz, kube-system/weave-net-z6qnn
node/cks8930 drained

Check current versions and upgrade plan:

➜ candidate@cks8930:~# sudo -i

➜ root@cks8930:~# kubelet --version
Kubernetes v1.31.5

➜ root@cks8930:~# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"32", GitVersion:"v1.32.1", GitCommit:"e9c9be4007d1664e68796af02b8978640d2c1b26", GitTreeState:"clean", BuildDate:"2025-01-15T14:39:14Z", GoVersion:"go1.23.4", Compiler:"gc", Platform:"linux/amd64"}

➜ root@cks8930:~# kubeadm upgrade plan
[preflight] Running pre-flight checks.
[upgrade/config] Reading configuration from the "kubeadm-config" ConfigMap in namespace "kube-system"...
[upgrade] Running cluster health checks
[upgrade] Fetching available versions to upgrade to
[upgrade/versions] Cluster version: 1.31.5
[upgrade/versions] kubeadm version: v1.32.1
[upgrade/versions] Target version: v1.32.1

Apply the upgrade:

➜ root@cks8930:~# kubeadm upgrade apply v1.32.1
[upgrade] Reading configuration from the "kubeadm-config" ConfigMap in namespace "kube-system"...
[upgrade] Use 'kubeadm init phase upload-config --config your-config.yaml' to re-upload it.
[upgrade/preflight] Running preflight checks
[upgrade] Running cluster health checks
[upgrade/preflight] You have chosen to upgrade the cluster version to "v1.32.1"
[upgrade/versions] Cluster version: v1.31.5
[upgrade/versions] kubeadm version: v1.32.1
[upgrade] Are you sure you want to proceed? [y/N]: y
...

Upgrade kubelet and kubectl:

➜ root@cks8930:~# apt update
➜ root@cks8930:~# apt install kubelet=1.32.1-1.1 kubectl=1.32.1-1.1
➜ root@cks8930:~# apt-mark hold kubelet kubectl
➜ root@cks8930:~# service kubelet restart

Verify the control plane upgrade:

➜ root@cks8930:~# k get node
NAME            STATUS                     ROLES           AGE   VERSION
cks8930         Ready,SchedulingDisabled   control-plane   22h   v1.32.1
cks8930-node1   Ready                                22h   v1.31.5

Uncordon the control plane node:

➜ root@cks8930:~# k uncordon cks8930
Step 3: Update Worker Node

First, drain the worker node:

➜ root@cks8930:~# k drain cks8930-node1 --ignore-daemonsets
node/cks8930-node1 cordoned
Warning: ignoring DaemonSet-managed Pods: kube-system/kube-proxy-gjtxp, kube-system/weave-net-l2pf8
...

Connect to the worker node and upgrade kubeadm:

➜ root@cks8930:~# ssh cks8930-node1

➜ root@cks8930-node1:~# apt update
➜ root@cks8930-node1:~# apt-mark unhold kubeadm
➜ root@cks8930-node1:~# apt install kubeadm=1.32.1-1.1
➜ root@cks8930-node1:~# apt-mark hold kubeadm

Upgrade the node configuration:

➜ root@cks8930-node1:~# kubeadm upgrade node

Upgrade kubelet and kubectl:

➜ root@cks8930-node1:~# apt-mark unhold kubectl kubelet
➜ root@cks8930-node1:~# apt install kubelet=1.32.1-1.1 kubectl=1.32.1-1.1
➜ root@cks8930-node1:~# service kubelet restart
Step 4: Verify the Upgrade

Check the node versions:

➜ root@cks8930:~# k get node
NAME            STATUS                     ROLES           AGE   VERSION
cks8930         Ready                      control-plane   22h   v1.32.1
cks8930-node1   Ready,SchedulingDisabled             22h   v1.32.1

Uncordon the worker node:

➜ root@cks8930:~# k uncordon cks8930-node1

➜ root@cks8930:~# k get node
NAME            STATUS   ROLES           AGE   VERSION
cks8930         Ready    control-plane   22h   v1.32.1
cks8930-node1   Ready              22h   v1.32.1
Summary of changes:
  • Upgraded control plane components to v1.32.1
  • Upgraded worker node components to v1.32.1
  • Verified all nodes are running the new version
  • Ensured all nodes are Ready and schedulable
Security Note: Keeping Kubernetes up to date is crucial for security. Each new version includes security patches and improvements. Always follow the official upgrade procedures and test in a non-production environment first.
Back to Questions List