I have seen a few articles about K3s and I decided to take a look at running it in my homelab.
Currently, I am running Harvester v1.2.1 on both of my servers. I know that Harvester has a very simple K3s spin up using Rancher, but I wanted this guide to serve people who are using other hypervisors.
With that being said, let’s dive in.
Hardware requirements scale based on the size of your deployments.
The Absolute Minimum Recommended Specs
CPU 1 core
RAM 512 MB
SSD 5 GB
According to the K3s Docs:
A single-node server installation is a fully-functional Kubernetes cluster, including all the datastore, control-plane, kubelet, and container runtime components necessary to host workload pods. It is not necessary to add additional server or agents nodes, but you may want to do so to add additional capacity or redundancy to your cluster.
~ docs.k3s.io
I decided that I was going to create a 3 node cluster.
I spun up 3 VMs on Harvester with the following specs:
1 CPU
2 GB RAM
25 GB SSD
Let’s get started on setting up the cluster.
SSHing into the 3 VMs, I ran the following:
sudo apt update && sudo apt upgrade -y && sudo apt -y autoremove && sudo apt -y autoclean
Really simply, this updates the OS and cleans out unnecesary packages. The OS image I am using is Ubuntu Jammy Minimal.
Let’s now run the following on the first node (init node?).
curl -sfL https://get.k3s.io | sh -
And just like that, we are in business.
Now, I want to download the kubeconfig file. The kubeconfig file is written to /etc/rancher/k3s/k3s.yaml. Make sure to replace 127.0.0.1 with the IP of your init node.
Success. We have access to the kube api using kubectl. We can see the kube api is being served at https://<your k3s node IP>:6443 (in my case https://10.0.0.123:6443).
Let’s add two other nodes.
We now need to run the following command on the other two nodes (worker nodes?):
curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -
Setting the K3S_URL parameter causes the installer to configure K3s as an agent, instead of a server. The K3s agent will register with the K3s server listening at the supplied URL. The value to use for K3S_TOKEN is stored at /var/lib/rancher/k3s/server/node-token on your server node.
In my case, the command looks like:
curl -sfL https://get.k3s.io | K3S_URL=https://10.0.0.123:6443 K3S_TOKEN=K1077e11f6676ee577ec0aec41424f686be1956edfee3a846c20139216ac8456602::server:43fdd78af727889d20c612f021b756c0 sh -
After running the command, we run kubectl get nodes
and we can see they have registered with the cluster.
Very cool. We now have a fully functional K3s cluster. I don’t have a stopwatch going, but this can easily be done in under 5 minutes.
Hopefully you found this little tutorial helpful. If you want to read more about K3s, head over to their docs.
Cheers,
Joe