This article will document how to deploy K3s to a cluster of Raspberry Pis.
I am using the following:
- One (1) Laptop (Running Ubuntu 21.10)
- Three (3) Raspberry Pis running Raspberry Pi OS, 64-bit (Debian 10 buster)
- Two (2) raspberry pi model 4s, with 8gb RAM
- One (1) Raspberry Pi 400 with 4gb RAM
- Each Pi is using a Samsung T7 SSD connected via USB 3.0 for storage
Make sure that each Raspberry Pi is running and accessible on the network. You will need a list of each Pi's IP address.
Install Ansible on the Laptop1
To configure the PPA on your machine and install Ansible run these commands:1
$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository --yes --update ppa:ansible/ansible
$ sudo apt install ansible
Build the Kubernetes cluster using k3s via Ansible2
https://k3s.io/ maintains an Ansible playbook that can set everything up for us.2
It is available here: https://github.com/k3s-io/k3s-ansible[^3]
Download and unzip the repository to the following location, /home/<user>/Downloads/k3s-ansible-master
.
Open a command line and navigate to the k3s-ansible-master
project directory:
$ cd /Downloads/k3s-ansible-master
Edit the hosts.ini
file,
$ nano inventory/sample/hosts.ini
It needs to contain IP addresses for each Raspberry Pi node in our cluster:
Example:
[master]
10.32.25.224
[node]
10.32.25.111
10.32.25.159
[k3s_cluster:children]
master
node
Now edit the group_vars/all.yml
file to supply the Ansible username.
$ nano inventory/sample/group_vars/all.yml
Example:
---
k3s_version: v1.17.5+k3s1
ansible_user: <username>
systemd_dir: /etc/systemd/system
master_ip: "{{ hostvars[groups['master'][0]]['ansible_host'] | default(groups['master'][0]) }}"
extra_server_args: ""
extra_agent_args: ""
Remove the config files from the sample directory.
$ mv inventory/sample/* inventory/
Run the following command to start the Ansible playbook:
$ ansible-playbook site.yml -i inventory/hosts.ini
Note: I actually couldn't get this to work using SSH passwordless authentication. I resorted to using the following command:
$ ansible-playbook site.yml -K -i inventory/hosts.ini
The -K
option prompts for the password before the playbook kicks off. Using this method it finished without error.
Download the latest release with the command:3
$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
Install kubectl:3
$ sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
$ scp <user>@master_ip:~/.kube/config ~/.kube/pi-cluster-config
Note: you may need to create the ~/.kube
directory if it doesnt already exist.
Set an environment variable to tell kubectl
to use our pi-cluster-config
file,
$ export KUBECONFIG=~/.kube/pi-cluster-config
Now you can run the following command to see if your pi cluster is up and running:
$ kubectl get nodes
It should return something like this:
NAME STATUS ROLES AGE VERSION
silverfox Ready master 95m v1.17.5+k3s1
whitefoot Ready <none> 95m v1.17.5+k3s1
cleareyes Ready <none> 95m v1.17.5+k3s1
A big shoutout to Jeff Geerling for making the youtube video and tutorial that inspired this article.4
Footnotes
-
Video Raspberry Pi Cluster Ep 3 - Installing Kubernetes (K3s) on the Turing Pi
Publication: Jeff Geerling's Youtube Channel
Author(s): Jeff Geerling
Date: May 21, 2020 ↩