Rancher 2.4 is the latest version of Rancher, in which you can upgrade your K3s cluster through the Rancher UI.
K3s is a lightweight Kubernetes distribution with which you can set up your development Kubernetes environment in minutes. It is well suited for production use cases, primarily for IoT and Edge devices.
In Rancher 2.4, you can import a K3s cluster and manage it through Rancher itself. In this tutorial, you’ll learn how to perform a live upgrade on a running K3s cluster.
Step1: create a K3s cluster
Before performing the upgrade, we need to start a K3s cluster. In this article I started on a CentOS VM, which you can do on any cloud.
Log in to the VM and run the following command:
**[root@demo3 ~]# curl - sfL [https://get.k3s.io] (https://get.k3s.io) | INSTALL_K3S_VERSION = "v1.0.1" sh - s - * *
[INFO] Using v1.0.1 as release
[INFO] Downloading hash[https://github.com/rancher/k3s/releases/download/v1.0.1/sha256sum-amd64.txt] (HTTP: / / https://github.com/rancher/k3s/releases/do Wnload/v1.0.1 / sha256sum - amd64. TXT)/INFO Downloading binary [https://github.com/rancher/k3s/releases/download/v1.0.1/k3s] (HTTP: / / https://github.com/rancher/k3s/releases/download/v1.0.1/k3 s) [INFO] Verifying binary download [INFO] Installing k3s to /usr/local/bin/k3s
[INFO] Creating /usr/local/bin/kubectl symlink to k3s
[INFO] Creating /usr/local/bin/crictl symlink to k3s
[INFO] Creating /usr/local/bin/ctr symlink to k3s
[INFO] Creating killall script /usr/local/bin/k3s-killall.sh
[INFO] Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO] env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO] systemd: Creating service file /etc/systemd/system/k3s.service
[INFO] systemd: Enabling k3s unit
Created symlink from /etc/systemd/system/multi-user.target.wants/k3s.service to /etc/systemd/system/k3s.service.
[INFO] systemd: Starting k3sAbove will install k3s version
**[root@demo3 ~]# kubectl get nodes**NAME STATUS ROLES AGE VERSION demo3 Ready master 5M55s **v1.16.3-k3sCopy the code
You can see that we have Kubernetes V1.16.3 installed on the VM.
Step2: Install Rancher
In order to perform an upgrade from the Rancher UI, Rancher must be installed with the following command:
**[root@demo3 ~]# sudo docker run -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher
**Unable to find image 'rancher/rancher:latest' locally
Trying to pull repository docker.io/rancher/rancher ...
latest: Pulling from docker.io/rancher/rancher
5bed26d33875: Pull complete
f11b29a9c730: Pull complete
930bda195c84: Pull complete
78bf9a5ad49e: Pull complete
fdb587a45dfe: Pull complete
0c3f7647a659: Pull complete
02c5407ca821: Pull complete
ebc009758b56: Pull complete
57a6e40f0f6e: Pull complete
30a88d01aca6: Pull complete
76505b705d6f: Pull complete
e585ea16af8d: Pull complete
6b069694034e: Pull complete
8c5d309f94d1: Pull complete
8ec56f5fa6c2: Pull complete
75872eb736b7: Pull complete
e774fd043162: Pull complete
c76d81e7a658: Pull complete
49bf6b83af1c: Pull complete
Digest: sha256:248ddca1169e8a4e06babd50e8105cbba0a326f86ec4de3e38d61e8909ffdb4e
Status: Downloaded newer image for docker.io/rancher/rancher:latest
ef7f9a0d5bca831af19900a6ceafd30daca51e4f951295762cf7516e48d3d742
Copy the code
Step3: import the cluster in Rancher
Open the Rancher UI and import the K3s cluster by clicking the following button:
Copy the last command and run it on the VM where K3s is installed:
**[root@demo3 ~]# curl --insecure -sfL [https://185.136.232.236/v3/import/pxv5g7xswnnqkhl4dx7nrn8swndwshk9g8426lnldrvt7vjvfc2fgr.yaml] (HTTP: / / https://185.136.232.236/ v3/import/pxv5g7xswnnqkhl4dx7nrn8swndwshk9g8426lnldrvt7vjvfc2fgr.yaml) | kubectl apply -f -**
clusterrole.rbac.authorization.k8s.io/proxy-clusterrole-kubeapiserver created
clusterrolebinding.rbac.authorization.k8s.io/proxy-role-binding-kubernetes-master created
namespace/cattle-system created
serviceaccount/cattle created
clusterrolebinding.rbac.authorization.k8s.io/cattle-admin-binding created
secret/cattle-credentials-d6e5b6d created
clusterrole.rbac.authorization.k8s.io/cattle-admin created
deployment.apps/cattle-cluster-agent created
daemonset.apps/cattle-node-agent created
Copy the code
Step4 perform the upgrade
Click on the three dots and select Edit. Select the latest version of Kubernetes and click Save.
After clicking Save, you can see that the cluster status changes from Active to Upgrading.
After a while, the status will change back to Active and you will see the K3s cluster upgraded to the latest version.
With just a few clicks, we have upgraded the imported K3s cluster directly to version V1.17.4 via the Rancher UI.
Troubleshooting
After practice, community users find that K3s cluster will stay in the status of Upgrading for a long time. After local operation of Rancher’s community Technology manager in China, the solutions are as follows:
K3s are divided into master and Agent roles. After the K3s cluster is successfully started, it can be imported to Rancher Server for management. If the Rancher Server and K3s master are on the same node, upgrading the K3s version on the Rancher UI will fail.
In addition, due to the logic of https://github.com/rancher/k3s-upgrade/blob/v1.18.4+k3s1/scripts/upgrade.sh#L15, grep when they upgrade two processes, K3s in Rancher Server and K3s in K3s master.
To resolve the above problems, stop the Rancher Server and start Rancher Server after the K3s upgrade succeeds.
conclusion
Rancher’s K3s is light and easy to use, and with Rancher 2.4 support, upgrading a cluster is a breeze. When you import a K3s cluster through the Rancher UI, Rancher automatically detects and enables the upgrade cluster option with a list of available versions. With this feature, you can upgrade any K3s cluster, whether it is self-managed or hosted on the cloud.