Skip to content

Instantly share code, notes, and snippets.

@Swackles
Last active November 11, 2022 21:05
Show Gist options
  • Select an option

  • Save Swackles/193ea9fa6f00b46957f21d5f3117e2cc to your computer and use it in GitHub Desktop.

Select an option

Save Swackles/193ea9fa6f00b46957f21d5f3117e2cc to your computer and use it in GitHub Desktop.
Rasberry Pi tutorials

Raspberry pi tutorials

Table of Contents

K3S

Installing

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.

1. Update the packages and install the new updates

sudo apt update && sudo apt upgrade -y

2. Enable memory cgroup

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

3. Reboot the pi

sudo reboot

4. Install the k3s

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.

5. Verify that k3s is installed by running

sudo kubectl get nodes

6. Copy master node token

Do this only when you're installing the master node

sudo cat /var/lib/rancher/k3s/server/node-token



Connecting k3s cluster to your PC

1. Copy the kubernetes config

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.

2. Verify that context

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

3. Switch to the k3s config

kubectl config use-context <name of the context>

4. Verify connection

kubectl get nodes

By running the command you should see all the attached nodes to your cluster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment