How to upgrade k3s with existing config file

A few years ago I switched from microk8s to k3s on my server. I described the setup process here: Switch from microk8s to k3s. Since then I had to upgrade k3s a few times and I always do not rember how I did it last time. So I thought it might be a good idea to write down the steps I did to upgrade k3s with an existing config file.

The upgrade process generally is documented in Upgrading k3s. Unfortunately I think this doesn’t cover the case when you have an existing configuration file very well.

When I did the upgrade the first time I found out that it’s a good idea to use a configuration file for k3s instead using K3S_* or INSTALL_K3S_* environment variables or command line arguments. So here is the configuration file I use. You can find the previous configuration with environmen variables in the comment:

/etc/rancher/k3s/config.yaml
1
2
3
4
5
6
7
# K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="--flannel-backend=none --cluster-cidr=192.168.0.0/16 --disable-network-policy --disable=traefik" sh -\
write-kubeconfig-mode: "0644"
flannel-backen: "none"
cluster-cidr: "192.168.0.0/16"
disable:
  - "traefik"
disable-network-policy: true
Note
You can find more about this at Configuration File.

Then you can just run the k3s installation script for the upgrade:

1
curl -sfL https://get.k3s.io | sh -

That’s it. I additionally had to update my kubeconfig:

1
2
3
4
5
cd
cd .kube
rm -rf *
copy /etc/rancher/k3s/k3s.yaml config
chmod 700 config