Kubernetes Version Upgrade
In this document, upgrading the Kubernetes application from version 1.26.3 to version 1.27.3 in the Ubuntu operating system is explained as an example.
When upgrading 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
1) Upgrade for Control Plane (Master) Node
Switch to the master (control-plane) presentation and follow steps 1-a,b and c.
Before starting the upgrade process, check the kubeadm, kubelet and kubectl versions with the commands below.
kubeadm version
kubelet --version
kubectl version --client
1-a) Kubeadm Version upgrade
You can view the list of available versions using the following command.
sudo apt-cache madison kubeadm
Current versions are displayed as v1.26 in the output above. Add the Version 1.27 repository to the system.
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.27/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.27/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
Install version 1.27.3-1.1 for Kubeadm.
sudo apt-mark unhold kubeadm
sudo apt-get install -y kubeadm=1.27.3-1.1
sudo apt-mark hold kubeadm
"FATAL: this version of kubeadm only supports deploying clusters with the control plane version >= 1.x Current version: v1.y"
If you encounter a similar error (x > y) condition,
As stated at the beginning of the document, perform version transitions one by one. If two or more versions are installed above, you can downgrade the kubeadm version with the command provided below.
If you want to switch to 1.25 while using version 1.26, use this command:
sudo apt-get install -y kubeadm=1.25.3-1.1 --allow-downgrades
The drain command below puts a specified Kubernetes node into maintenance mode and migrates 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 may not apply this process for clusters with only one node.
kubectl drain <MASTER_NODE_NAME> --ignore-daemonsets
Upgrade Kubeadm to the installed v1.27 version with the upgrade command.
sudo kubeadm upgrade apply v1.27.3
You should see the message on the screen indicating that the operation was successful.
Make the node usable again.
kubectl uncordon <MASTER_NODE_NAME>
1-b) Kubelet and Kubectl Version upgrade
sudo apt-mark unhold kubelet kubectl
sudo apt-get install -y kubelet=1.27.3-1.1 kubectl=1.27.3-1.1
sudo apt-mark hold kubelet kubectl
1-c) Upgrade Process Check
Restart the kubelet service.
systemctl daemon-reload
systemctl restart kubelet
Run the command below to view the version of the node that is the master (control-plane).
kubectl get nodes
Check that the upgrade to version 1.27.3 is successful.
2) Upgrade for Worker Node
The version upgrade of the worker node is carried out with similar steps.
The drain command below puts a specified Kubernetes node into maintenance mode and migrates pods to other nodes. If you do not have an alternative node for your worker node, this command will cause a system outage. You may not apply this process for clusters with only one worker node.
The command is executed on the master (control-plane) server and initiates maintenance and pod evacuation for the worker node.
kubectl drain <WORKER_NODE_NAME> --ignore-daemonsets
2-a) Kubeadm Version Upgrade
Switch to the server where the worker node is located and perform the kubeadm upgrade with the following commands.
sudo apt-mark unhold kubeadm
sudo apt-get install -y kubeadm=1.27.3-1.1
sudo apt-mark hold kubeadm
Perform the upgrade process for the worker node.
sudo kubeadm upgrade node
2-b) Kubelet and Kubectl Version Upgrade
sudo apt-mark unhold kubelet kubectl
sudo apt-get install -y kubelet=1.27.3-1.1 kubectl=1.27.3-1.1
sudo apt-mark hold kubelet kubectl
2-c) Upgrade Process Control
systemctl daemon-reload
systemctl restart kubelet
Make the node available again by running the following command on the master (control-plane) node.
kubectl uncordon <WORKER_NODE_NAME>
Worker node'un versiyonunu görüntülemek için aşağıdaki komutu çalıştırınız.
kubectl get nodes
Check that the upgrade to version 1.27.3 is successful.