Upgrading K3S in Multipass

By | May 12, 2020

These are instructions on how to update a K3S cluster running in Multipass virtual machines. My installation of such a cluster is described in a previous article.The procedure will update K3S, both master and agent nodes, to the latest version of K3S.

Master Node

When updating the master node I take the opportunity to obtain the master node token, which will be needed when updating the agent nodes.

  • Make sure that all the Multipass instances of the K3S cluster are running.
  • Open a shell on the K3S master node VM.
multipass shell k3s-master
  • Update the K3S master node to the latest version.
    If the installed K3S version matches the latest version, no changes will be applied.
curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL=latest sh -
  • Inspect the current K3S version.
k3s -v

At the time of writing, the latest version is:

k3s version v1.18.2+k3s1 (698e444a)

  • Obtain the master node token.
    Copy it and store it – it will be needed in a little while when updating the K3S agent node(s).
sudo cat /var/lib/rancher/k3s/server/node-token
  • Exit the master node VM.
exit

Agent Nodes

Before updating the K3S agent node(s), there is a preparatory step that only need to be performed once.

  • Obtain the IP address of the K3S master node.
multipass list
Name                    State             IPv4             Image
k3s-agent01 Running 192.168.64.8 Ubuntu 18.04 LTS
k3s-agent02 Running 192.168.64.12 Ubuntu 18.04 LTS
k3s-master Running 192.168.64.7 Ubuntu 18.04 LTS

As can be seen, my K3S master node IP is 192.168.64.7.

The procedure described below is to be repeated for each K3S agent node that you have in your cluster.

  • Open a shell on a K3S agent node VM.
multipass shell k3s-agent01
  • Update the K3S agent node to the latest version.
    If the installed K3S version matches the latest version, no changes will be applied.
    Note that you have to replace the IP address in K3S_URL with your master node IP address and insert the master node token in the value of K3S_TOKEN, replacing [insert master node token here].
curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL=latest K3S_URL="https://192.168.64.7:6443" K3S_TOKEN="[insert master node token here]" sh -
  • Inspect the current K3S version.
k3s -v

The K3S version in the agent should be identical to that of the master node.

  • Exit the agent node VM.
exit

kubectl

In the kubectl documentation, the following can be read:

You must use a kubectl version that is within one minor version difference of your cluster. For example, a v1.2 client should work with v1.1, v1.2, and v1.3 master. Using the latest version of kubectl helps avoid unforeseen issues.

  • Inspect the current kubectl version.
kubectl version
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.5", GitCommit:"20c265fef0741dd71a66480e35bd69f18351daea", GitTreeState:"clean", BuildDate:"2019-10-15T19:16:51Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2+k3s1", GitCommit:"698e444a03fe3a705849fc8d9ad9e35f1dffe286", GitTreeState:"clean", BuildDate:"2020-05-07T00:18:01Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"linux/amd64"}

As can be seen, the kubectl version is v1.15.5 while the server version is v1.18.2 and thus kubectl need to be updated as well.

  • Download the latest version of kubectl.
    The following shows how to download the latest kubectl for OS X.
    Please refer to the kubectl installation instructions for instructions on how to download the latest kubectl for other operating systems.
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl"
  • Make the kubectl binary executable.
chmod +x kubectl
  • Move the kubectl binary to the directory containing binaries.
    Again, the command shown is for OS X.
sudo mv ./kubectl /usr/local/bin/kubectl
  • Verify the version of the installed kubectl.
kubectl version
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2", GitCommit:"52c56ce7a8272c798dbc29846288d7cd9fbae032", GitTreeState:"clean", BuildDate:"2020-04-16T11:56:40Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2+k3s1", GitCommit:"698e444a03fe3a705849fc8d9ad9e35f1dffe286", GitTreeState:"clean", BuildDate:"2020-05-07T00:18:01Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"linux/amd64"}

We can now see that the kubectl version is v1.18.2, which matches the server version.

Your K3S cluster is now up-to-date and ready for new adventures.

Happy coding!

Leave a Reply

Your email address will not be published.