In this document, a Kubernetes cluster version 1.18 is running on the current Linux operating system and works with Docker.

This document provides step-by-step instructions on how to upgrade this cluster from version 1.18 to 1.30.

When upgrading your Kubernetes version, each minor version between the current and target versions (e.g., from 1.25 to 1.26, then from 1.26 to 1.27, etc.) must be upgraded sequentially.

KUBERNETES:
v1.18      →  Current Version          
v1.30      →  Target Version     


Required Files:

v1.18 - v1.30        →   Kubectl, kubeadm, kubelet files
Kubernetes-cni    →   When upgrading from Kubernetes 1.18 to 1.19, it will be sufficient to install it once. There is no need to install it in versions 1.19 and above.
containerd 1.6     →   When upgrading to Kubernetes version 1.24, you must switch to using containerd. Containerd must be version 1.6 or higher, and Docker must be removed.


You can download the necessary files for Kubernetes from http://fss.apinizer.com/index.php/s/uWP0ewA2sf2rS02.

You can download the necessary file for Containerd from http://fss.apinizer.com/index.php/s/TSlg6gWm6Aq4LJy.

1) Version Upgrade

This step consists of the version upgrade sections “1.18-1.19,” “1.20-1.23,” and “1.24-1.30.”

Each section covers the version upgrade process and solutions to possible errors.

1.1) Upgrade from 1.18 to 1.19

Very Important

A flannel issue may arise during the transition from 1.18 to 1.19. Check the node status with the following command.

kubectl get nodes 
CODE

If the node status is NotReady, check the logs on the relevant server using the following command.

journalctl -xeu kubelet
CODE

Solution:

Transfer the flannel file from any server (master or worker) to the server you are upgrading using the scp command.

scp /opt/cni/bin/flannel  <USERNAME>@<NODE_IP>:/opt/cni/bin


When you check the node status, you should see “READY.”

Upgrade for Control Plane (Master) Node

Switch to the master (control plane) instance and follow the steps below.

Before starting the upgrade process, check the versions of kubeadm, kubelet, and kubectl using the following commands.

kubeadm version
kubelet --version
kubectl version --client
POWERSHELL
Kubeadm Version upgrade

Let's remove package pinning for Kubeadm.

sudo apt-mark unhold kubeadm
CODE


Go to the folder where you extracted the file you downloaded from https://fss.apinizer.com.

cd 1.19.3
CODE

Let's download the .deb extension kubeadm file inside.

sudo dpkg -i kubeadm_1.19.3-00_amd64.deb
sudo apt-mark hold kubeadm
CODE

The following drain command takes the specified Kubernetes node into maintenance mode and transfers the pods to other nodes. If you do not have an alternative master node for your master (control-plane) node, this command will cause a system outage. You cannot apply this process to single-node clusters.

kubectl drain <MASTER_NODE_NAME> --ignore-daemonsets 
POWERSHELL

Upgrade Kubeadm to version v1.19.3 using the upgrade command.

#Change the version part in each version.
sudo kubeadm upgrade apply v1.19.3
CODE

You should see a message on the screen indicating that the operation was successful.

Make the node reusable again.

kubectl uncordon <MASTER_NODE_NAME>
POWERSHELL
Kubelet and Kubectl Version Upgrade
sudo apt-mark unhold kubelet kubectl
sudo dpkg -i kubelet_1.19.3-00_amd64.deb
sudo dpkg -i kubectl_1.19.3-00_amd64.deb
sudo apt-mark hold kubelet kubectl
POWERSHELL

Restart the Kubelet service.

systemctl daemon-reload
systemctl restart kubelet
POWERSHELL

To view the version of the master (control plane) node, run the following command.

kubectl get nodes
POWERSHELL

Check that the upgrade to version  has been successful.

Upgrade for Worker Node

The worker node version upgrade is performed using similar steps.

The following drain command puts the specified Kubernetes node into maintenance mode and transfers the pods to other nodes. If you do not have an alternative node for your worker node, this command will cause a system outage. You cannot apply this process to clusters with a single worker node.

The command is executed on the master (control plane) server and initiates maintenance and pod draining for the worker node.

kubectl drain <WORKER_NODE_NAME> --ignore-daemonsets
POWERSHELL

Switch to the server where the worker node is located and perform the kubeadm upgrade using the following commands.

Go to the folder where you extracted the file you downloaded from https://fss.apinizer.com.

sudo apt-mark unhold kubeadm
sudo dpkg -i kubeadm_1.19.3-00_amd64.deb
sudo apt-mark hold kubeadm
CODE

Perform the upgrade process for the worker node.

sudo kubeadm upgrade node
POWERSHELL

Kubelet and Kubectl Version Upgrade

sudo apt-mark unhold kubelet kubectl
sudo dpkg -i kubelet_1.19.3-00_amd64.deb
sudo dpkg -i kubectl_1.19.3-00_amd64.deb
sudo apt-mark hold kubelet kubectl
POWERSHELL


systemctl daemon-reload
systemctl restart kubelet
POWERSHELL

Run the following command on the master (control plane) node to make the node available again.

kubectl uncordon <WORKER_NODE_NAME> 
POWERSHELL

To view the version of the worker node, run the following command.

kubectl get nodes
POWERSHELL

1.2) Upgrade from 1.20 to 1.23

Versions 1.20-1.23 are updated individually.

Upgrade for Control Plane (Master) Node

Switch to the master (control plane) instance and follow the steps below.

Before starting the upgrade process, check the versions of kubeadm, kubelet, and kubectl using the following commands.

kubeadm version
kubelet --version
kubectl version --client
POWERSHELL
Kubeadm Version upgrade

Let's remove package pinning for Kubeadm.

sudo apt-mark unhold kubeadm
CODE


Go to the folder where you extracted the file you downloaded from https://fss.apinizer.com.

cd 1.20.4
CODE

Let's download the .deb extension kubeadm file inside.

sudo dpkg -i kubeadm_1.20.4-00_amd64.deb
sudo apt-mark hold kubeadm
CODE

The following drain command takes the specified Kubernetes node into maintenance mode and transfers the pods to other nodes. If you do not have an alternative master node for your master (control-plane) node, this command will cause a system outage. You cannot apply this process to single-node clusters.

kubectl drain <MASTER_NODE_NAME> --ignore-daemonsets 
POWERSHELL

Upgrade Kubeadm to version v1.20.4 using the upgrade command.

#Change the version part in each version.
sudo kubeadm upgrade apply v1.20.4
CODE

You should see a message on the screen indicating that the operation was successful.

Make the node reusable again.

kubectl uncordon <MASTER_NODE_NAME>
POWERSHELL
Kubelet and Kubectl Version Upgrade
sudo apt-mark unhold kubelet kubectl
sudo dpkg -i kubelet_1.20.4-00_amd64.deb
sudo dpkg -i kubectl_1.20.4-00_amd64.deb
sudo apt-mark hold kubelet kubectl
POWERSHELL

Restart the Kubelet service.

systemctl daemon-reload
systemctl restart kubelet
POWERSHELL

To view the version of the master (control plane) node, run the following command.

kubectl get nodes
POWERSHELL

Check that the upgrade to version  has been successful.

Upgrade for Worker Node

The worker node version upgrade is performed using similar steps.

The following drain command puts the specified Kubernetes node into maintenance mode and transfers the pods to other nodes. If you do not have an alternative node for your worker node, this command will cause a system outage. You cannot apply this process to clusters with a single worker node.

The command is executed on the master (control plane) server and initiates maintenance and pod draining for the worker node.

kubectl drain <WORKER_NODE_NAME> --ignore-daemonsets
POWERSHELL

Switch to the server where the worker node is located and perform the kubeadm upgrade using the following commands.

Go to the folder where you extracted the file you downloaded from https://fss.apinizer.com.

sudo apt-mark unhold kubeadm
sudo dpkg -i kubeadm_1.20.4-00_amd64.deb
sudo apt-mark hold kubeadm
CODE

Perform the upgrade process for the worker node.

sudo kubeadm upgrade node
POWERSHELL

Kubelet and Kubectl Version Upgrade

sudo apt-mark unhold kubelet kubectl
sudo dpkg -i kubelet_1.20.4-00_amd64.deb
sudo dpkg -i kubectl_1.20.4-00_amd64.deb
sudo apt-mark hold kubelet kubectl
POWERSHELL


systemctl daemon-reload
systemctl restart kubelet
POWERSHELL

Run the following command on the master (control plane) node to make the node available again.

kubectl uncordon <WORKER_NODE_NAME> 
POWERSHELL

To view the version of the worker node, run the following command.

kubectl get nodes
POWERSHELL

Transition to Containerd: Kubernetes 1.24 and above

If docker is used instead of containerd in the current system, the transition to containerd should be made at this step.

Containerd version 1.6.x or higher is required.


Note: If Containerd is currently in use, skip the “Containerd Transition Steps” step and continue with the “1.3) Upgrade from 1.24 to 1.30” step.


Containerd Transition Phases:

Note: Perform this on machines with Docker installed.


Docker is stopped. Packages are deleted.

sudo systemctl stop docker.service
sudo systemctl disable docker.service

sudo apt remove docker*
CODE

The version of Containerd and whether it is installed are checked.

containerd --version
CODE


If you do not have version 1.6 or higher installed, download the .deb extension containerd file from the link provided at the beginning of the document.

Run the following command in the directory where the downloaded file is located.

sudo dpkg -i containerd.io*.deb
CODE


The Kubeadm-flags.env file opens.

sudo vi /var/lib/kubelet/kubeadm-flags.env

#Alttaki satır varsa silinir
--network-plugin=cni  

#Alttaki satır yoksa eklenir
--container-runtime-endpoint=unix:///var/run/containerd/containerd.sock
CODE

The necessary lines are added to the crictl.yaml file.

sudo tee /etc/crictl.yaml <<EOF
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 10
debug: false
EOF
CODE

Final settings are made and the container is started.

sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml

sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml

# Restart containerd
sudo systemctl restart containerd
sudo systemctl enable containerd
systemctl status containerd
CODE

1.3) Upgrade from 1.24 to 1.30

Versions 1.24-1.30 are updated individually.

Upgrade for Control Plane (Master) Node

Switch to the master (control plane) instance and follow the steps below.

Before starting the upgrade process, check the versions of kubeadm, kubelet, and kubectl using the following commands.

kubeadm version
kubelet --version
kubectl version --client
POWERSHELL
Kubeadm Version upgrade

Let's remove package pinning for Kubeadm.

sudo apt-mark unhold kubeadm
CODE

Go to the folder where you extracted the file you downloaded from https://fss.apinizer.com.

cd 1.24.3
CODE

Let's download the .deb extension kubeadm file inside.

sudo dpkg -i kubeadm_1.24.3-00_amd64.deb
sudo apt-mark hold kubeadm
CODE

The following drain command puts the specified Kubernetes node into maintenance mode and transfers the pods to other nodes. If you do not have an alternative master node for your master (control-plane) node, this command will cause a system outage. You cannot apply this process to single-node clusters.

kubectl drain <MASTER_NODE_NAME> --ignore-daemonsets 
POWERSHELL

Upgrade Kubeadm to version v1.20.4 using the upgrade command.

# Change the version part in each version.
sudo kubeadm upgrade apply v1.24.3
CODE

You should see a message on the screen indicating that the operation was successful.

Make the node reusable again.

kubectl uncordon <MASTER_NODE_NAME>
POWERSHELL
Kubelet and Kubectl Version Upgrade
sudo apt-mark unhold kubelet kubectl
sudo dpkg -i kubelet_1.24.3-00_amd64.deb
sudo dpkg -i kubectl_1.24.3-00_amd64.deb
sudo apt-mark hold kubelet kubectl
POWERSHELL

Restart the Kubelet service.

systemctl daemon-reload
systemctl restart kubelet
POWERSHELL

To view the version of the master (control plane) node, run the following command.

kubectl get nodes
POWERSHELL

Check that the upgrade to version  has been successful.

Upgrade for Worker Node

The worker node version upgrade is performed using similar steps.

The following drain command puts the specified Kubernetes node into maintenance mode and transfers the pods to other nodes. If you do not have an alternative node for your worker node, this command will cause a system outage. You cannot apply this process to clusters with a single worker node.

The command is executed on the master (control plane) server and initiates maintenance and pod draining for the worker node.

kubectl drain <WORKER_NODE_NAME> --ignore-daemonsets
POWERSHELL

Switch to the server where the worker node is located and perform the kubeadm upgrade using the following commands.

Go to the folder where you extracted the file you downloaded from https://fss.apinizer.com.

sudo apt-mark unhold kubeadm
sudo dpkg -i kubeadm_1.24.3-00_amd64.deb
sudo apt-mark hold kubeadm
CODE

Perform the upgrade process for the worker node.

sudo kubeadm upgrade node
POWERSHELL

Kubelet and Kubectl Version Upgrade

sudo apt-mark unhold kubelet kubectl
sudo dpkg -i kubelet_1.24.3-00_amd64.deb
sudo dpkg -i kubectl_1.24.3-00_amd64.deb
sudo apt-mark hold kubelet kubectl
POWERSHELL


systemctl daemon-reload
systemctl restart kubelet
POWERSHELL

Run the following command on the master (control plane) node to make the node available again.

kubectl uncordon <WORKER_NODE_NAME> 
POWERSHELL

To view the version of the worker node, run the following command.

kubectl get nodes
POWERSHELL

Cluster Status Check:

You can view your new cluster information with the following commands.

kubectl cluster-info
kubectl get node -o wide
CODE