544 lines
19 KiB
Org Mode
544 lines
19 KiB
Org Mode
# -*- ii: ii; -*-
|
||
#+TITLE: Raspberry pi k3s cluster guide
|
||
#+AUTHOR: James Blair
|
||
#+EMAIL: mail@jamesblair.net
|
||
#+DATE: 24th December 2019
|
||
|
||
|
||
This file serves as a complete step by step guide for creating a bare metal raspberry pi kubernetes cluster using [[https://k3s.io/][k3s]] from [[https://rancher.com/][Rancher]].
|
||
|
||
My goal for this build is to replace a server I currently run at home that hosts several workloads via Docker with a scalable k3s cluster.
|
||
|
||
Additionally in future I would like the cluster to be portable and operate via 3G-5G Cellular network and an array of batteries.
|
||
|
||
I chose k3s as it incredibly lightweight but still CNCF certified and production grade software that is optimised for resource constraints of raspberry pis.
|
||
|
||
|
||
* Pre-requisites
|
||
|
||
** Cluster machines
|
||
|
||
For this guide I am using four [[https://www.pishop.us/product/raspberry-pi-4-model-b-4gb/][Raspberry Pi 4 4GB]] machines.
|
||
|
||
The cluster will have two leader nodes and two worker nodes.
|
||
|
||
For resiliency puposes in future I will consider updateing the cluster to run with all nodes as leader nodes.
|
||
|
||
|
||
** Boot media
|
||
|
||
This guide requires each Raspberry Pi to have a removable SD card or other removable boot media. I am using four 32GB SD Cards though any USB or SD card at least 8GB in size should work fine.
|
||
|
||
*** TODO Migration to network booting
|
||
|
||
In future it would be preferable for the raspberry pi's to be able to network boot and setup automatically without an SD card.
|
||
|
||
This is a nice to have that I will pursue at a later date once I have a deployed cluster that allows me to migrate off the current server setup I have deployed.
|
||
|
||
|
||
* Step 1 - Prepare boot media for master
|
||
|
||
** Download the latest release
|
||
|
||
Our first step is to create the bootable SD Card with a minimal install of [[https://www.raspbian.org/][Raspbian]], which is a free operating system based on [[https://www.debian.org/][Debian]] and is optimised for Raspberry Pi hardware.
|
||
|
||
Rather than doing an installation and configuration of an os image from scratch I found [[https://github.com/FooDeas/raspberrypi-ua-netinst][this project]] on Github which automates the install and configuration process nicely.
|
||
|
||
#+NAME: Download the latest release zip
|
||
#+begin_src tmate
|
||
echo Downloading latest release zip from github
|
||
curl -s https://api.github.com/repos/foodeas/raspberrypi-ua-netinst/releases/latest \
|
||
| grep "browser_download_url.*zip" \
|
||
| cut -d : -f 2,3 \
|
||
| tr -d \" \
|
||
| wget -i -
|
||
|
||
echo Checking file is now present
|
||
ls -l | grep *.zip
|
||
|
||
echo Extracting the zip file
|
||
unzip -q -d installer *.zip
|
||
ls -l | grep installer
|
||
#+end_src
|
||
|
||
#+RESULTS: Download the latest release zip
|
||
#+begin_example
|
||
Downloading latest release zip from github
|
||
Checking file is now present
|
||
-rw-rw-rw- 1 james james 60299545 Aug 12 08:35 raspberrypi-ua-netinst-v2.4.0.zip
|
||
Extracting the zip file
|
||
drwxrwxrwx 1 james james 4096 Jan 20 11:12 installer
|
||
-rwxrwxrwx 1 james james 2863 Jan 10 17:04 installer-config.txt
|
||
#+end_example
|
||
|
||
|
||
** Apply custom install configuration
|
||
|
||
Our next step after downloading the latest release is to apply our own installation configuration using a simple txt file.
|
||
|
||
There is great documentation online howing what configuration options are available [[https://github.com/malignus/raspberrypi-ua-netinst/blob/master/doc/INSTALL_CUSTOM.md][here]].
|
||
|
||
For our purposes we just over-write the file downloaded and extracted in the previous step with one we have prepared earlier :)
|
||
|
||
#+NAME: Overwrite installer configuration file
|
||
#+begin_src tmate
|
||
echo Display wordcount of original file for comparison
|
||
wc installer/raspberrypi-ua-netinst/config/installer-config.txt
|
||
|
||
echo Overwriting /installer/raspberrypi-ua-netinst/config/installer-config.txt
|
||
cp installer-config.txt installer/raspberrypi-ua-netinst/config/
|
||
|
||
echo Display wordcount of file after copy to validate update
|
||
wc installer/raspberrypi-ua-netinst/config/installer-config.txt
|
||
#+end_src
|
||
|
||
#+RESULTS: Overwrite installer configuration file
|
||
#+begin_example
|
||
Display wordcount of original file for comparison
|
||
3 23 157 installer/raspberrypi-ua-netinst/config/installer-config.txt
|
||
Overwriting /installer/raspberrypi-ua-netinst/config/installer-config.txt
|
||
Display wordcount of file after copy to validate update
|
||
67 85 2863 installer/raspberrypi-ua-netinst/config/installer-config.txt
|
||
#+end_example
|
||
|
||
|
||
** Apply custom post install script
|
||
|
||
The final step is to supply a post install script which completes additional security hardening and production readiness automatically.
|
||
|
||
To supply a script we can provide an additional ~post-install.txt~ file as documented [[https://github.com/FooDeas/raspberrypi-ua-netinst/blob/devel/doc/INSTALL_ADVANCED.md][here]].
|
||
|
||
I have a hardening script prepared in this repository that we can copy in.
|
||
|
||
#+NAME: Copy in post-install script
|
||
#+begin_src tmate
|
||
echo Copying in post-install.txt
|
||
cp post-install.txt installer/raspberrypi-ua-netinst/config/
|
||
|
||
echo Display wordcount of file after copy to validate
|
||
wc installer/raspberrypi-ua-netinst/config/post-install.txt
|
||
#+end_src
|
||
|
||
#+RESULTS: Copy in post-install script
|
||
#+begin_example
|
||
Copying in post-install.txt
|
||
Display wordcount of file after copy to validate
|
||
98 282 3429 installer/raspberrypi-ua-netinst/config/post-install.txt
|
||
#+end_example
|
||
|
||
|
||
* Step 2 - Copy the install media to sd card
|
||
|
||
Our next step is to copy the contents of the ~installer/~ folder to a *FAT32* formatted removable media i.e. SD Card.
|
||
|
||
Unfortunately this is currently a windows step as my dev environment is a Windows 10 laptop with Debian via Windows Subsystem for Linux which does not support ~lsblk~ or other disk management commands.
|
||
|
||
** Obtain sd card partition information
|
||
|
||
Our first step is to insert the SD Card and ensure it is formatted correctly as ~FAT32~. To do that we need to know the number of the disk we want to format, we can find that via powershell.
|
||
|
||
#+NAME: Get disks via windows powershell
|
||
#+begin_src tmate
|
||
echo Retrieving disk list via powershell
|
||
powershell.exe -nologo -command "get-disk | select Number, FriendlyName, Size"
|
||
#+end_src
|
||
|
||
#+NAME: Get partitions via windows powershell
|
||
#+begin_src tmate
|
||
echo Retrieving partition list via powershell
|
||
powershell.exe -nologo -command "get-disk | get-partition | select PartitionNumber, DriveLetter, Size, Type"
|
||
#+end_src
|
||
|
||
#+RESULTS: Get disks via windows powershell
|
||
#+begin_example
|
||
Retrieving disk list via powershell
|
||
|
||
PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\Debian\home\james\Documents\raspi-k3s> get-disk | select Number, FriendlyName, Size
|
||
|
||
Number FriendlyName Size
|
||
------ ------------ ----
|
||
1 Realtek PCIE Card Reader 31104958464
|
||
0 SAMSUNG MZVLB256HAHQ-000H1 256060514304
|
||
|
||
|
||
|
||
PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\Debian\home\james\Documents\raspi-k3s>
|
||
|
||
PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\Debian\home\james\Documents\raspi-k3s> echo Retrieving partition list via powershell
|
||
Retrieving
|
||
partition
|
||
list
|
||
via
|
||
powershell
|
||
|
||
PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\Debian\home\james\Documents\raspi-k3s> get-disk | get-partition | select PartitionNumber, DriveLetter, Size, Type
|
||
|
||
PartitionNumber DriveLetter Size Type
|
||
--------------- ----------- ---- ----
|
||
1 D 134217728 FAT32
|
||
2 |