Upgrading a Kubernetes Cluster using kubeadm
Tags: kubernetes, cloudnative, opensource
Published: 2023-05-03 12:21:23

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

## Prerequisites

* We need a working Kubernetes cluster created using kubeadm
    
* If you haven’t created the cluster, please check my previous article below  
    This will guide you to create a Kubernetes v1.27.0 cluster
    
    {% embed https://dev.to/iamunnip/building-a-kubernetes-cluster-using-kubeadm-goh %}
    

## Steps

### Control Plane

* Verify the version of our cluster by executing the below command in the **\[control-plane\]** instance
    

```bash
$ 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
```

* Update the package index and find the latest kubeadm patch available in the repository
    

```bash
$ sudo apt update

$ sudo apt-cache madison kubeadm
```

* Unhold the kubeadm package for upgrading
    

```bash
$ sudo apt-cache unhold kubeadm
```

* Upgrade the kubeadm package to version v1.27.1 and hold the package from automatic upgrading
    

```bash

$ sudo apt install -y kubeadm=1.27.1-00

$ sudo apt-mark hold kubeadm
```

* Check the upgraded kubeadm version and verify the upgrade plan
    

```bash
$ sudo kubeadm version

$ sudo kubeadm upgrade plan
```

* Once our plan is verified, we can upgrade the **\[control-plane\]** by executing the below command
    

```bash
$ sudo kubeadm upgrade apply v1.27.1
```

* Prepare the **\[control-plane\]** node for maintenance by marking it unschedulable and evicting the workloads
    

```bash
$ kubectl drain control-plane --ignore-daemonsets
```

* Unhold the kubelet and kubectl packages for an upgrade
    

```bash
$ sudo apt-mark unhold kubelet kubectl
```

* Upgrade kubelet and kubectl packages to version v1.27.1 and hold the packages from automatic upgrading
    

```bash
$ sudo apt install kubelet=1.27.1-00 kubectl=1.27.1-00

$ sudo apt-mark hold kubelet kubectl
```

* Restart the kubelet on **\[control-plane\]**
    

```bash
$ sudo systemctl daemon-reload

$ sudo systemctl restart kubelet
```

* Uncordon the **\[control-plane\]** for marking it as schedulable
    

```bash
$ kubectl uncordon control-plane
```

* Verify the nodes, now we can see **\[control-plane\]** is upgraded to v1.27.1
    

```bash
$ 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
```

## Nodes

* Update the package index on **\[node-1\]** and unhold the kubeadm package for upgrading
    

```bash
$ sudo apt update

$ sudo apt-mark unhold kubeadm
```

* Upgrade the kubeadm package to version v1.27.1 on **\[node-1\]** and hold the package from automatic upgrading
    

```bash
$ sudo apt install kubeadm=1.27.1-00

$ sudo apt-mark hold kubeadm
```

* Upgrade the cluster configuration on **\[node-1\]** using the below command
    

```bash
$ sudo kubeadm upgrade node
```

* Prepare the **\[node-1\]** for maintenance by marking it unschedulable and evicting the workloads  
    Execute the below drain command on **\[control-plane\]**
    

```bash
$ kubectl drain node-1 --ignore-daemonsets --force
```

* Unhold the kubelet and kubectl packages for upgrade
    

```bash
$ sudo apt-mark unhold kubelet kubectl
```

* Upgrade kubelet and kubectl packages to version v1.27.1 and hold the packages from automatic upgrading
    

```bash
$ sudo apt install kubelet=1.27.1-00 kubectl=1.27.1-00

$ sudo apt-mark hold kubelet kubectl
```

* Restart the kubelet on **\[node-1\]**
    

```bash
$ sudo systemctl daemon-reload

$ sudo systemctl restart kubelet
```

* Uncordon the **\[node-1\]** for marking it as schedulable  
    Execute the below uncordon command on **\[control-plane\]**
    

```bash
$ kubectl uncordon node-1
```

* 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\]**
    

```bash
$ 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
```

## Reference

[https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/](https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/)

[https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/upgrading-linux-nodes/](https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/upgrading-linux-nodes/)