k3s

k3s is a lightweight kubernetes distribution. It is also used as the runtime for Rancher Desktop.

You can install it by running the script on its site.

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

In this process, the systemd setting is completed, and k3s will start automatically when the system starts.

upgrade

Upgrade k3s process is the same as installation.

context

kubeconfig is generated in /etc/rancher/k3s/k3s.yaml after installation.
Merging it with an existing config, you can operate the local k3s cluster by switching the context with the kube config subcommand.

# Personalize config to each user.
$ sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/
$ sudo chown <user>:<user> ~/.kube/k3s.yaml

# Change context label to "k3s"
$ sed -i -e 's/default/k3s/g' k3s.yaml

$ KUBECONFIG=~/.kube/config:~/.kube/k3s.yaml kubectl config view --flatten > ~/.kube/merged
# Replace config
$ mv ~/.kube/merged ~/.kube/config

Shutdown Failure

Power off and reboot may be slow after installing k3s.
systemd-shutdown hangs on containerd-shim when k3s-agent running #2400 can be related.

In essence, cleaning up the container proccess properly at shutdown is needed.
As for the subject, there is a workaround that forces systemd to terminate by shortening the DefaultTimeoutStopSec in /etc/systemd/system.conf.

However, since systemd of Ubuntu 20.04 has this bug that does not read config. It takes always 90 seconds until the complete termination.

kube-system starting error

Occasionally, kube-system containers may have failed to start, in which case the containers will be out of network.
You can reboot system containers with a command like the following:

$ kubectl rollout restart -nkube-system deploy/coredns
$ kubectl rollout restart -nkube-system deploy/local-path-provisioner
$ kubectl rollout restart -nkube-system deploy/metrics-server

Impression

k3s runs without VMs on Linux host, so it’s more stable than Rancher Desktop.
You can even direct access to k3s containers with extra tweaks.

⁋ May 16, 2022↻ Sep 2, 2024
中馬崇尋
Chuma Takahiro