This part goes over installing K3S on a Raspberry pi. It is recommended that you install the master node first and then install worker nodes.
sudo apt update && sudo apt upgrade -y
Open the file in nano
sudo nano /boot/cmdline.txt
And then add to the end of the file
cgroup_memory=1 cgroup_enable=memory
sudo reboot
If you're installing a master node use the command
curl -sfL https://get.k3s.io | sh -
and if you're installing a worker node use command
curl -sfL https://get.k3s.io | K3S_URL=https://<IP_ADDRESS>:6443 K3S_TOKEN=<TOKEN> sh -
Replace <IP_ADDRESS> with the IP address of the master node and <TOKEN> with the token you got from the master node.
If you're installing the worker nodes, you can skip the last two steps, but as a very last step you should check your master node and verify that all nodes are attached.
NB! Sometimes the download succeedes, but the k3s cannot launch. If this happens, just reboot the device.
sudo kubectl get nodes
Do this only when you're installing the master node
sudo cat /var/lib/rancher/k3s/server/node-token
In your master node, copy the contents of your k3s.yaml file
sudo cat /etc/rancher/k3s/k3s.yaml
The context will look something like this:
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: Tm90aGluZyB0byBzZWUgaGVyZSA7KQ==
server: https://127.0.0.1:6443
name: default
contexts:
- context:
cluster: default
user: default
name: default
current-context: default
kind: Config
preferences: {}
users:
- name: default
user:
client-certificate-data: QWxtb3N0IGdvdCB0aGUgY2VydGlmaWNhdGU=
client-key-data: R2V0IGhhY2tlZA==You only need to keep the clusters, context and users array elements, the rest can be deleted. Next you need to change the cluster.server IP address to the IP address of your clusters master node. It is also recommended to change the default names to something else.
By the end it should look something like this.
- cluster:
certificate-authority-data: Tm90aGluZyB0byBzZWUgaGVyZSA7KQ==
server: https://<IP address of your master node>:6443
name: pi
- context:
cluster: pi
user: pi
name: pi
- name: pi
user:
client-certificate-data: QWxtb3N0IGdvdCB0aGUgY2VydGlmaWNhdGU=
client-key-data: R2V0IGhhY2tlZA==Now copy this into the local kubeconfig.
Make sure the context you saved is available, if you run the command
kubectl config get-contexts
You should see a context with the name you set, if you didn't change the name, it should be default
kubectl config use-context <name of the context>
kubectl get nodes
By running the command you should see all the attached nodes to your cluster.