Installing k3s with some configuration

5 July, 2023 - Tags: kubernetes


TLDR

curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" sh -s - --disable=traefik

Default k3s Installation

I used to install k3s for development/testing purpose on a remote machine and I use to do it very often say multiple times a day. I used to use the following script in my mind and to an extend, I had this ready on my fingertips to be invoked without looking at docs. This was working great but this has a downside.

Occasionally, I used to get this error message.

$ kubectl get pods 
WARN[0000] Unable to read /etc/rancher/k3s/k3s.yaml, please start server with --write-kubeconfig-mode to modify kube config permissions 
error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied

I used to solve this problem by invoking the following command.

chmod 644 /etc/rancher/k3s/k3s.yaml
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml

And the problem was that, I needed to do this every time I ssh into the system.

Installing with 644

I looked at the docs and found my solution. I moved to this script and afterwards I didn't encountered the error.

curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" sudo sh

You can avoid sudo to be more secure but since this is an ephemeral machine, I tend to care less about security on this machine and the main intention is to get things done.

Disabling traefik

If you've used k3s for a while then you would have noticed that k3s by default installs traefik as an ingress controller. I almost never use this but it's still there in the cluster and this is not required. You can disable this using the appropriate flag.

curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" sh -s - --disable=traefik