Skip to content

Instantly share code, notes, and snippets.

@ericboehs
Last active April 13, 2022 02:21
Show Gist options
  • Save ericboehs/b716a998b4f73dc7679bfed38e2ad71e to your computer and use it in GitHub Desktop.
Save ericboehs/b716a998b4f73dc7679bfed38e2ad71e to your computer and use it in GitHub Desktop.
Installing Kubernetes (k3s) on Raspberry Pi 4b 2GB+

How to set up Kubernetes on one or more Raspberry Pis (4b)

Estimated time needed: one hour. And then several more hours to have fun with it.

Set up Pi

Go through this section for all of your Raspberry Pis (master and nodes).

  1. Install Raspberry Pi OS 64-bit Lite onto an SD card using Raspberry Pi's Imager.
    • In the imager options, I configured hostname, ssh, username, but not Wi-Fi. Setting up Wi-Fi disables ethernet.
  2. Add SD, ethernet, and power to Pi. 🔌
  3. After boot, configure DHCP server to assign a fixed IP (in your router).
  4. SSH to your pi, enable containers, iptables, and then reboot:
    ssh pi-k3s-master.local -t sudo su
    sed -i '$s/$/ cgroup_memory=1 cgroup_enable=memory/' /boot/cmdline.txt
    apt-get install -y iptables-persistent
    update-alternatives --set iptables /usr/sbin/iptables-legacy
    update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
    reboot

Set up Master

  1. SSH to your master node and install k3s:
    curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION='v1.21.11+k3s1' K3S_KUBCONFIG_MODE="644" sh -s
    • I installed 1.21 because I wanted to use Rancher and it doesn't support 1.22/1.23 yet. You can omit the version number here if you don't ranch.

If you don't have any nodes, you're done.

Set up Nodes

For each node, SSH in and install k3s (it will detect it's a node based on the env vars set):

export K3S_TOKEN="$(ssh pi-k3s-master.local sudo cat /var/lib/rancher/k3s/server/node-token)"; \
  curl -sfL https://get.k3s.io | K3S_URL="https://10.0.1.90:6443" INSTALL_K3S_VERSION='v1.21.11+k3s1' sh -
  • The export line pulls the token from the master node, change it to your master's hostname.
  • Make sure your nodes are using unique hostnames (pi-k3s-node1, pi-k3s-node2, etc).
    • I did this in the Raspberry Pi Imager options.
  • The K3S_URL seems to need an IP rather than a domain name (pi-k3s-master.local didn't work).

Screw up?

  1. You can uninstall:
    • Master: /usr/local/bin/k3s-uninstall.sh
    • Node: /usr/local/bin/k3s-agent-uninstall.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment