When you are managing Kubernetes in the real world, it is essential that you are able to keep your cluster up to date. This lab will allow you to practice the process of upgrading a Kubernetes cluster to a newer Kubernetes version using kubeadm. This will ensure you are comfortable with the upgrade process and ready to manage real-world Kubernetes clusters.
You are working for BeeBox, a subscription service company that provides weekly shipments of bees to customers. The company is using Kubernetes to run some of their applications, but a new version of Kubernetes has been released.
Your task is to upgrade Kubernetes. The cluster has one control plane server and two worker nodes. Upgrade all Kubernetes components on all three servers to Kubernetes version 1.27.2-1.1
.
Log in to the control plane server using the credentials provided:
ssh cloud_user@<CONTROL_PLANE_SERVER_PUBLIC_IP_ADDRESS>
Note: We'll be switching between nodes throughout the lab, so be sure to check the Bash prompt for which node to run the commands on.
-
Upgrade kubeadm:
sudo apt-get update && \ sudo apt-get install -y --allow-change-held-packages kubeadm=1.27.2-1.1
-
Make sure it upgraded correctly:
kubeadm version
-
Drain the control plane node:
kubectl drain k8s-control --ignore-daemonsets
-
Plan the upgrade:
sudo kubeadm upgrade plan v1.27.2
-
Upgrade the control plane components:
sudo kubeadm upgrade apply v1.27.2
-
Upgrade kubelet and kubectl on the control plane node:
sudo apt-get update && \ sudo apt-get install -y --allow-change-held-packages kubelet=1.27.2-1.1 kubectl=1.27.2-1.1
-
Restart kubelet:
sudo systemctl daemon-reload
sudo systemctl restart kubelet
-
Uncordon the control plane node:
kubectl uncordon k8s-control
-
Verify the control plane is working:
kubectl get nodes
If it shows a
NotReady
status, run the command again after a minute or so. It should becomeReady
.
Note: In a real-world scenario, you should not perform upgrades on all worker nodes at the same time. Make sure enough nodes are available at any given time to provide uninterrupted service.
-
Run the following on the control plane node to drain worker node 1:
kubectl drain k8s-worker1 --ignore-daemonsets --force
You may get an error message that certain pods couldn't be deleted, which is fine.
-
In a new terminal window, log in to worker node 1:
ssh cloud_user@<WORKER_1_PUBLIC_IP_ADDRESS>
-
Upgrade kubeadm on worker node 1:
sudo apt-get update && \ sudo apt-get install -y --allow-change-held-packages kubeadm=1.27.2-1.1
kubeadm version
-
Back on worker node 1, upgrade the kubelet configuration on the worker node:
sudo kubeadm upgrade node
-
Upgrade kubelet and kubectl on worker node 1:
sudo apt-get update && \ sudo apt-get install -y --allow-change-held-packages kubelet=1.27.2-1.1 kubectl=1.27.2-1.1
-
Restart kubelet:
sudo systemctl daemon-reload
sudo systemctl restart kubelet
-
From the control plane node, uncordon worker node 1:
kubectl uncordon k8s-worker1
-
From the control plane node, drain worker node 2:
kubectl drain k8s-worker2 --ignore-daemonsets --force
-
In a new terminal window, log in to worker node 2:
ssh cloud_user@<WORKER_2_PUBLIC_IP_ADDRESS>
-
Upgrade kubeadm:
sudo apt-get update && \ sudo apt-get install -y --allow-change-held-packages kubeadm=1.27.2-1.1
kubeadm version
-
Back on worker node 2, perform the upgrade:
sudo kubeadm upgrade node
sudo apt-get update && \ sudo apt-get install -y --allow-change-held-packages kubelet=1.27.2-1.1 kubectl=1.27.2-1.1
sudo systemctl daemon-reload
sudo systemctl restart kubelet
-
From the control plane node, uncordon worker node 2:
kubectl uncordon k8s-worker2
-
Still in the control plane node, verify the cluster is upgraded and working:
kubectl get nodes
If they show a
NotReady
status, run the command again after a minute or so. They should becomeReady
.