DEV Community

Cover image for Upgrading a Kubernetes Cluster using kubeadm
Unni P
Unni P

Posted on • Originally published at iamunnip.hashnode.dev

Upgrading a Kubernetes Cluster using kubeadm

In this article, we will look how we can upgrade a Kubernetes cluster using kubeadm

Prerequisites

Steps

Control Plane

  • Verify the version of our cluster by executing the below command in the [control-plane] instance
$ kubectl get nodes
NAME            STATUS   ROLES           AGE    VERSION
control-plane   Ready    control-plane   7m5s   v1.27.0
node-1          Ready    <none>          91s    v1.27.0
node-2          Ready    <none>          17s    v1.27.0
Enter fullscreen mode Exit fullscreen mode
  • Update the package index and find the latest kubeadm patch available in the repository
$ sudo apt update

$ sudo apt-cache madison kubeadm
Enter fullscreen mode Exit fullscreen mode
  • Unhold the kubeadm package for upgrading
$ sudo apt-cache unhold kubeadm
Enter fullscreen mode Exit fullscreen mode
  • Upgrade the kubeadm package to version v1.27.1 and hold the package from automatic upgrading

$ sudo apt install -y kubeadm=1.27.1-00

$ sudo apt-mark hold kubeadm
Enter fullscreen mode Exit fullscreen mode
  • Check the upgraded kubeadm version and verify the upgrade plan
$ sudo kubeadm version

$ sudo kubeadm upgrade plan
Enter fullscreen mode Exit fullscreen mode
  • Once our plan is verified, we can upgrade the [control-plane] by executing the below command
$ sudo kubeadm upgrade apply v1.27.1
Enter fullscreen mode Exit fullscreen mode
  • Prepare the [control-plane] node for maintenance by marking it unschedulable and evicting the workloads
$ kubectl drain control-plane --ignore-daemonsets
Enter fullscreen mode Exit fullscreen mode
  • Unhold the kubelet and kubectl packages for an upgrade
$ sudo apt-mark unhold kubelet kubectl
Enter fullscreen mode Exit fullscreen mode
  • Upgrade kubelet and kubectl packages to version v1.27.1 and hold the packages from automatic upgrading
$ sudo apt install kubelet=1.27.1-00 kubectl=1.27.1-00

$ sudo apt-mark hold kubelet kubectl
Enter fullscreen mode Exit fullscreen mode
  • Restart the kubelet on [control-plane]
$ sudo systemctl daemon-reload

$ sudo systemctl restart kubelet
Enter fullscreen mode Exit fullscreen mode
  • Uncordon the [control-plane] for marking it as schedulable
$ kubectl uncordon control-plane
Enter fullscreen mode Exit fullscreen mode
  • Verify the nodes, now we can see [control-plane] is upgraded to v1.27.1
$ kubectl get nodes
NAME            STATUS   ROLES           AGE    VERSION
control-plane   Ready    control-plane   118m   v1.27.1
node-1          Ready    <none>          112m   v1.27.0
node-2          Ready    <none>          111m   v1.27.0
Enter fullscreen mode Exit fullscreen mode

Nodes

  • Update the package index on [node-1] and unhold the kubeadm package for upgrading
$ sudo apt update

$ sudo apt-mark unhold kubeadm
Enter fullscreen mode Exit fullscreen mode
  • Upgrade the kubeadm package to version v1.27.1 on [node-1] and hold the package from automatic upgrading
$ sudo apt install kubeadm=1.27.1-00

$ sudo apt-mark hold kubeadm
Enter fullscreen mode Exit fullscreen mode
  • Upgrade the cluster configuration on [node-1] using the below command
$ sudo kubeadm upgrade node
Enter fullscreen mode Exit fullscreen mode
  • Prepare the [node-1] for maintenance by marking it unschedulable and evicting the workloads Execute the below drain command on [control-plane]
$ kubectl drain node-1 --ignore-daemonsets --force
Enter fullscreen mode Exit fullscreen mode
  • Unhold the kubelet and kubectl packages for upgrade
$ sudo apt-mark unhold kubelet kubectl
Enter fullscreen mode Exit fullscreen mode
  • Upgrade kubelet and kubectl packages to version v1.27.1 and hold the packages from automatic upgrading
$ sudo apt install kubelet=1.27.1-00 kubectl=1.27.1-00

$ sudo apt-mark hold kubelet kubectl
Enter fullscreen mode Exit fullscreen mode
  • Restart the kubelet on [node-1]
$ sudo systemctl daemon-reload

$ sudo systemctl restart kubelet
Enter fullscreen mode Exit fullscreen mode
  • Uncordon the [node-1] for marking it as schedulable Execute the below uncordon command on [control-plane]
$ kubectl uncordon node-1
Enter fullscreen mode Exit fullscreen mode
  • Repeat the above steps for [node-2] also

  • Now our cluster is fully upgraded to v1.27.1

    Verify the same by executing the below command on [control-plane]

$ kubectl get nodes
NAME            STATUS   ROLES           AGE    VERSION
control-plane   Ready    control-plane   136m   v1.27.1
node-1          Ready    <none>          131m   v1.27.1
node-2          Ready    <none>          129m   v1.27.1
Enter fullscreen mode Exit fullscreen mode

Reference

https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/

https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/upgrading-linux-nodes/

Top comments (0)