Skip to main content

Install K3s

Now we have the base OS/node settings configured and ready, we can get on to installing K3s.

Why are we using K3s and not K8s?

TL:DR - K8s in its full fat flavour is heavy in both computer and memory resources. K3s is not.

Longer version - K3s is a stripped back version of K8s, removing many extra components that are not generally used in most deployments, replacing others with more efficient ones - you can add the 'stock' components back if you would like, but generally speaking, you don't need to.
K3s is a great way to get started with K8s at home, on smaller commodity grade hardware as a result.

Step 1 - Install K3s on first Node

The first thing we need to do is to initialize the cluster. We do this on the first node.

To do this, we need to generate a token to use on the cluster, which you can do this with the following website, picking something from 160bit upwards.
Next, substitute the variables for the token you generated, into the command below.

curl -sfL https://get.k3s.io | sh -s - server --token=ABC123 --cluster-init --disable servicelb --write-kubeconfig-mode 644 --disable-cloud-controller --disable local-storage

What about the extra variables, what do they do?

VariablePurpose
--cluster-initInitializes cluster
--disable servicelbDisables ServiceLB - we don't need this
--write-kubeconfig-mode 644This allows writing to the kubeconfig file, which is useful for allowing a K3s cluster to be imported into Rancher.
--disable-cloud-controllerDisable k3s default cloud controller manager - we don't need this
--disable local-storageDisables the usage of local storage as a storage class - we don't need this as we will be using either Longhorn or NFS for persistent storage

You can read up on the other variables you can use, here.

Step 2 - Configure your admin workstation to connect to your cluster

First, download and install kubectl for your OS of choice -

Next, we need to get a config for you to use with kubectl.
In the SSH session on Node 1, run the following -

cat /etc/rancher/k3s/k3s.yaml

Copy its output and in your workstations user profile, create a folder (if it doesnt exist already) called .kube, creating a file within called 'config' (no extension).
Paste the output of the cat command into the config file.
Next, look for the line that says server, under the section - cluster: and replace the https://127.0.0.1:6443 address with the IP of your first node.
This will let you use kubectl from your admin workstation.

You can test this works by running -

kubectl get nodes

X

Step 3 - Install K3s on extra nodes

Next, we should get the extra nodes added in.
SSH to the nodes and run the following command -

`curl -sfL https://get.k3s.io | sh -s - server --token=ABC123 --server https://RPi-K3s-Node01:6443 --disable servicelb --write-kubeconfig-mode 644 --disable-cloud-controller --disable local-storage`

The extra variable we are setting here --server basically tells our other nodes where the first node is, so it can join the cluster.

Watch Progress

Once you have ran the K3s command on the extra nodes, you can watch from the first node their join progress with the following command -

watch kubectl get nodes

You can CTRL+C to quit out of this view.

Step 4 - Install Helm

Next, we should install helm on your admin workstation.
This is a package manager of sorts for Kubernetes.
You can download and configure with the steps below, dependant on your operating system -

You can confirm it is installed with the command helm version, which should output its version if successful.

Next Step

Next go to the next step, Networking.
Or,
Go back to the index page.