# Installing K3s
## Master node
We are going to install the K3s version of Kubernetes, that is lightweight enough for out single board computers to handle. Use the following command to download and initialize K3s’ master node.
curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644 --disable servicelb --token some_random_password --node-taint CriticalAddonsOnly=true:NoExecute --bind-address 192.168.0.80 --disable-cloud-controller --disable local-storage
Some explanations:
–write-kubeconfig-mode 644 - This is the mode that we want to use for the kubeconfig file. Its optional, but needed if you want to connect to Rancher manager later on.
–disable servicelb - This is the flag that we want to use to disable the service load balancer.
–token - This is the token that we want to use to connect to the K3s master node. Choose a random password, but keep remember it.
–node-taint - This is the flag that we want to use to add a taint to the K3s master node. I'll explain taints later on, but it will mark the node to not run any containers except the ones that are critical.
–bind-address - This is the flag that we want to use to bind the K3s master node to a specific IP address.
–disable-cloud-controller - This is the flag that we want to use to disable the K3s cloud controller. I don't think I need it.
–disable local-storage - This is the flag that we want to use to disable the K3s local storage (for the moment).
We can look at Kubernetes nodes by using the following command:
root@control01:~# kubectl get nodes NAME STATUS ROLES AGE VERSION master Ready control-plane,master 23s v1.23.6+k3s1
## Workers
To install the worker nodes, we first need to obtain the K3S_TOKEN from the master node. Execute the command shown below to retrieve it:
# get node-token from master node sudo cat /var/lib/rancher/k3s/server/node-token
# The result is something likes this K109d3581cbb7da137b25c2e2ea0a47e941cdb2380799f9cd5840fd059abac1b9a6::server:6961dd195c22c88b06d38a238d7ebc4b
We need to join some workers the easyest (not the best way to do it) is install K3s on every node:
curl -sfL https://get.k3s.io | K3S_URL=https://192.168.0.80:6443 K3S_TOKEN="K109d3581cbb7da137b25c2e2ea0a47e941cdb2380799f9cd5840fd059abac1b9a6::server:6961dd195c22c88b06d38a238d7ebc4b" sh -
The IP and the token were the ones in the master node, it´s necessary to adapt it for every particular installation
Now give it few moments to join the cluster. You can watch the progress by using the following command:
watch kubectl get nodes
To quit watch use Ctrl+c
In the end, it should look something like this:
root@control01:~# kubectl get nodes NAME STATUS ROLES AGE VERSION worker01 Ready <none> 71s v1.23.6+k3s1 worker02 Ready <none> 72s v1.23.6+k3s1 worker03 Ready <none> 61s v1.23.6+k3s1 master Ready control-plane,master 3m45s v1.23.6+k3s1
# Setting role/labels
We can tag our cluster nodes to give them labels.
Let's add this tag key:value: kubernetes.io/role=worker to worker nodes. This is more cosmetic, to have nice output from kubectl get nodes.
kubectl label nodes worker01 kubernetes.io/role=worker kubectl label nodes worker02 kubernetes.io/role=worker kubectl label nodes worker03 kubernetes.io/role=worker #Another label/tag. I will use this one to tell deployments #to prefer nodes where node-type equals workers. #The node-type is our chosen name for key, you can call it whatever. kubectl label nodes worker01 node-type=worker kubectl label nodes workerS02 node-type=worker