In this topic, we will look at the step-by-step instructions to upgrade the following on the control plane node.
- Control plane components
- Kubelet
- kubectl
Upgrade Control Plane Components
Step 1: SSH in to the control plane node
To upgrade the control plane, ssh in to the control plane node.
Step 2: Upgrade Kubeadm to the latest version
Update the package repo.
sudo apt-get update -y
Unhold kubeadm package. The unhold
flag removes a hold placed on kubeadm package during the cluster setup. A hold is a status that prevents the package from being automatically installed, upgraded, or removed.
sudo apt-mark unhold kubeadm
You can check the latest available version using the following command.
sudo apt-cache madison kubeadm | tac
Install the latest version. Replace 1.29.2-1.1
with the most recent version you find in the above output.
sudo apt-get install -y kubeadm=1.29.2-1.1
Verify the kubeadm version using the following command.
kubeadm version -o json
Step 3: Check the upgrade plan
Now, we need to run the Kubeadm upgrade plan to check if we can upgrade the cluster to the latest version.
kubeadm upgrade plan
Based on the output, choose a target version from the plan. For example, if the example output shows the target version as v1.29.2
, select this version. The output will also provide the upgrade command along with the version number.
Step 4: Apply Kubeadm Upgrade
Now we can apply the upgrade using the following command. Replace v1.29.2 with the correct version.
sudo kubeadm upgrade apply v1.29.2
Verify the upgrade version and type y
When you run the command, kubeadm checks the role of the node (whether it’s a control plane node or a worker node). The upgrade process varies slightly depending on the node’s role.
If the node is a controlplane node, it upgrades the necessary control plane components like kube-apiserver, kube-controller-manager, and kube-scheduler to the new version.
The API server is typically upgraded first, followed by the controller manager and scheduler. During the upgrade, there may be a brief period where the API server is unavailable
Step 5: Hold the kubeadm package
Now we will hold the kubeadm package to prevent upgrades.
sudo apt-mark hold kubeadm
Step 6: Verify the upgrade
kubeadm version -o json
You should see the upgraded version as shown below.
$ kubeadm version -o json
{
"clientVersion": {
"major": "1",
"minor": "29",
"gitVersion": "v1.29.2",
"gitCommit": "4b8e819355d791d96b7e9d9efe4cbafae2311c88",
"gitTreeState": "clean",
"buildDate": "2024-02-14T10:39:04Z",
"goVersion": "go1.21.7",
"compiler": "gc",
"platform": "linux/arm64"
}
}
Upgrade Kubelet and Kubectl
Follow the steps given below to upgrade kubelet
and kubectl
on the control plane
Step 1: Get the control plane node name.
kubectl get nodes
Step 2: Drain the control plane node using the node name and make it unschedulable. Here, controlplane
is the node name. If you have a different name for your control plane, rename it accordingly..
k drain controlplane --ignore-daemonsets
--ignore-daemonsets
: This ignores DaemonSet-managed pods, which cannot be killed automatically.
Step 3: Now, unhold Kubelet and kubectl
sudo apt-mark unhold kubelet kubectl
Step 4: Update and install using the same version you used for kubeadm. Replace 1.29.2-0
with your latest version.
sudo apt-get update -y
sudo apt-get install kubelet=1.29.2-1.1 kubectl=1.29.2-1.1
Step 5: Restart kubelet systemd service using the following commands.
sudo systemctl daemon-reload
sudo systemctl restart kubelet
Step 5: Uncordon the node so that the control plane becomes schedulable.
k uncordon controlplane