The next step is to install K3s, which is simple enough:
- log in to your app server as your local user
- run the following command:
sudo curl -sfL https://get.k3s.io | sh -s - --disable=traefik
- have some patience.
Once this is done you can see the status of your “cluster” with “kubectl get nodes”:
lemmy@akari:~> kubectl get nodes NAME STATUS ROLES AGE VERSION appsrv Ready control-plane,master 7d22h v1.20.4+k3s1
One thing worth talking about is –disable=traefik which I’ll do in the next part.
Let me just mention this page, which helped me a lot at this point.
Now there are some little tweaks that you might want to consider doing:
- Disabling IPv6 on your appserver:
I found that after a reboot some of the services on my appserver would fail to start properly. In the system journal I could see them complain about invalid certificates, and on closer inspection I found that the pods tried to talk to each other using IPv6, but the self-signed certificates that K3s had generated didn’t include the right IPv6 information. The fix was simple enough, create a file /etc/sysctl.d/98-disable-ipv6.conf with a single line in it: “net.ipv6.conf.all.disable_ipv6=1”, then restart the server and you’ll find all pods running properly now. - Making your K3s accessible for the regular local user without having to use sudo:
By default the configuration files in /etc/rancher are only readable for root, so the local unprivileged user needs sudo. That can get a bit annoying, because a lot of tutorials that you’ll might want to follow once your K3s is up and running only mention the “naked” kubectl commands, so if you copy&paste them they’ll fail. Solution: create the environment file for the k3s service in /etc/systemd/system/k3s.service.env and put one line in it:mathias@appsrv:~$ sudo cat /etc/systemd/system/k3s.service.env K3S_KUBECONFIG_MODE="644"
After a restart of K3s you should be able to use kubectl as the regular user without sudo.
- Make your K3s accessible from other hosts, i.e. your desktop computer:
Once your regular user on your k3s host can use kubectl without sudo you can then copy the config file ~/.kube/config to other hosts and install kubectl on those. Make sure you edit that config file and change the server url to point at the right IP address.
Continued here.
1 thought on “From 0 to Kubernetes – Step 2, deploying K3s”