How I Upgraded A Production Grade Kubernetes Cluster From 1.23.17 To 1.24.17 using Kubeadm

0

Kubernetes

Kubernetes, image credit - thelinuxnotes

In this article, I will share my experience in upgrading a bare metal Production grade Kubernetes cluster from 1.23.17 -> 1.24.17 using Kubeadm. The process is quite straightforward, however, there are some gotchas I encountered and I have documented them here, which may be helpful to you.

The process is in 2 parts:

  • Upgrade the Control Plane Nodes
  • Upgrade the Worker Nodes

First, run kubectl get nodes -o wide to see all the nodes.

Kubernetes Control Plane Upgrade: 1.23.17 -> 1.24.17

  • Drain the node:

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

  • ssh into the node, then run the next commands to add the necessary keys and update the node:
ssh -i ~/.ssh/key <user>@<ip>

echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.24/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.24/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

chmod +x /etc/apt/keyrings/kubernetes-apt-keyring.gpg

apt update
For The First Master Node
  • Run the following command to list the available k8s versions:

apt-cache madison kubeadm | grep 1.24

  • Run the command to upgrade kubeadm
apt-mark unhold kubeadm && 
apt-get update && 
apt-get install -y kubeadm='1.24.17-1.1' && 
apt-mark hold kubeadm
  • Run the command to upgrade the node:

kubeadm upgrade apply v1.24.17 --ignore-preflight-errors=CoreDNSUnsupportedPlugins

  • Run the command to upgrade kubelet and kubectl and then finally restart the kubelet:
apt-mark unhold kubelet kubectl && 
sudo apt-get update && 
sudo apt-get install -y kubelet='1.24.17-1.1' kubectl='1.24.17-1.1' && 
sudo apt-mark hold kubelet kubectl && systemctl daemon-reload && 
systemctl restart kubelet
  • Uncordon the node:

kubectl uncordon <node>

For Each Of The Rest Of The Master Nodes
  • Drain the node:

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

  • ssh into the node

ssh -i ~/.ssh/key <user>@<ip>

  • Check available kubelet & kubectl versions(Minor version upgrade is ok e.g 1.24.17):

apt-cache madison kubeadm | grep 1.24

  • Run upgrade kubeadm
apt-mark unhold kubeadm && 
apt-get install -y kubeadm='1.24.17-00' && 
apt-mark hold kubeadm
  • Run the command to upgrade the node:

kubeadm upgrade node --ignore-preflight-errors=CoreDNSUnsupportedPlugins

  • Run the command to upgrade kubelet and kubectl and then finally restart the kubelet:
apt-mark unhold kubelet kubectl && 
apt-get update && 
apt-get install -y kubelet='1.24.17-00' kubectl='1.24.17-00' && 
apt-mark hold kubelet kubectl && 
systemctl daemon-reload && 
systemctl restart kubelet
  • Uncordon the node:

kubectl uncordon <node>

Kubernetes Worker Upgrade: 1.23.17 -> 1.24.17

For Each Of The Worker Nodes
  • Drain the node:

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

  • ssh into the node:

ssh -i ~/.ssh/key <user>@<ip>

  • Run the following command to list the available k8s versions:

apt update && apt-cache madison kubeadm | grep 1.24

  • Run the command to upgrade kubeadm, kubelet and kubectl and then finally restart the kubelet:
apt-mark unhold kubeadm && 
apt-get install -y kubeadm='1.24.17-1.1' && 
apt-mark hold kubeadm && kubeadm upgrade node && 
apt-mark unhold kubelet kubectl && 
apt-get install -y kubelet='1.24.17-1.1' kubectl='1.24.17-1.1' && 
apt-mark hold kubelet kubectl && systemctl daemon-reload && 
systemctl restart kubelet
  • Uncordon the node:

kubectl uncordon <node>

At this point, we have successfully upgraded the Kubernetes cluster from 1.23.17 -> 1.24.17.

kubernetesbare-metalupgrade 0 0

Leave a comment