### List of all the essential components - 4 x Raspberry Pi 4 Model B (RAM is your choice) - 4 x *good value* micro sd cards. I use [Silicon Power 3D 32GB](https://www.amazon.com/gp/product/B07RRX7XWF?th=1), as they are relatively cheap and work well with Rpis, but you are free to use whichever you want, just avoid unbranded or used. - 2 x [Power Banks](https://www.amazon.co.uk/gp/product/B08DXL8YQ7/) (if you use 3 Pis only, you can try using only one bank, as it is advertised as a triple 15W). Obviously, this is a suitable choice only if you need the cluster up for a few hours, otherwise you need a power outlet capable of 60W+ with 4 x 15W+ outputs. You could also use a PC 5V PSU and power the Pis through GPIO pins. If you have some money to splash out, you can think about buying a [PoE switch](https://www.amazon.co.uk/dp/B0769C24T1/), along with 4 x [Raspberry Pi PoE HAT](https://www.amazon.co.uk/GeeekPi-Raspberry-Support-standard-30x30x7mm/dp/B08MPZD47R), to power each board directly from its ethernet cable (total additional cost is around £70). - [4 x USB cables](https://www.aliexpress.com/item/1005001968128876.html). You don't need these cables if you're using a PoE switch. Actually, if you buy the power banks I suggested above, they are already included therein (although one is possibly a bit stretched). - [4 x network RJ45 Cat6 patch cables](https://www.amazon.co.uk/dp/B01J8MDV5G/) You can also [build them yourself](https://www.groundcontrol.com/galileo/ch5-ethernet.htm) - [5-port unmanaged Gigabit network switch](https://www.amazon.co.uk/gp/product/B07HP5TN4S) - [4-layers Raspberry Pi 4 Stackable Case](https://www.amazon.co.uk/GeeekPi-Raspberry-Cooling-Heatsink-Stackable/dp/B07Z4GRQGH) - a wired/wireless keyboard, only needed to text the initial command to initiate the `ssh` service. - An external laptop/desktop to manage the Pis headless. You can obviously work on the Pis themselves if you so prefer, but in that case you need at least a permanent keyboard and a monitor, switching cables between the Pis when needed. | Item | Seller | Quantity | Unit Cost | Total Cost | |====|====|====|====|====| | Raspberry Pi 4B 4GB | ebay.co.uk | 4 | 42.65 | 170.60 | | INIU Power Bank 10000mAh Tri-3A Outputs | amazon.co.uk | 2 | 11.99 | 23.98 | | TP-Link TL-SG105S 5-Port Ethernet Gigabit Switch | amazon.co.uk | 1 | 7.70 | 7.70 | | Cat 6 Ethernet Cable, Ancable 15cm (4 Pack) Flat | amazon.co.uk | 1 | 6.90 | 6.90 | | Silicon Power 3D SD Card 32 GB (pack of 5)| amazon.com | 1 | 31.47 | 31.47 | | GeeekPi Pi Rack Case with Cooling Fan and Heatsink, 4 Layers | aliexpress.com | 1 | 11.20 | 11.20 | ### Setup Flash the most recent [Raspberry Pi OS Lite](https://www.raspberrypi.org/software/operating-systems/) image on each SD card, using [BalenaEtcher](https://www.balena.io/etcher/). Insert one card in each pi, gear up ethernet, HDMI, keyboard and power cables, then follow the next few steps for each of them. - find the Raspberry Pi’s IP address in the booting output log. - enable 'ssh' server (use the hardware connected keyboard): ``` sudo touch /boot/ssh sudo reboot ``` - once rebooted, you can connect using a terminal `ssh pi@[IP-ADDRESS]`, or with an appropriate client software, like [Putty]() or [MobaXterm]() on Windows. The default username is `pi` and the default password is `raspberry`. - add new user: ``` sudo su adduser username usermod -aG sudo username reboot ``` - delete `pi` user: ``` { login as username } sudo userdel -r pi ``` - change *hostname* editing the following two files (enter master or worker[x], x = 1,2,3): ``` sudo nano /etc/hostname sudo nano /etc/hosts sudo reboot ``` - update the system: ``` sudo apt update sudo apt -y full-upgrade ``` - install some prerequisite tools: ``` sudo apt -y install net-tools ssh ufw dirmngr gnupg apt-transport-https ca-certificates software-properties-common build-essential nano dos2unix man-db git-core libgit2-dev libauthen-oath-perl openssh-server libsocket6-perl ``` - enable the firewall: ``` sudo ufw enable sudo ufw allow 22 ``` - to change the current dynamic ip address with a static one (in my case: 192.168.0.11x, x = 0,1,2,3), start with opening the configuration file: ``` sudo nano /etc/dhcpcd.conf ``` then scroll down and change the following lines as required by your situation: ``` interface eth0 static ip_address=192.168.0.11x/24 static routers=192.168.0.1 static domain_name_servers=192.168.0.1 8.8.8.8 8.8.4.4 ``` where: - **interface** defines which network interface you are setting the configuration for (`eth0` is wired, `wlan0` is wireless) - **static ip_address** is the IP address that you want to set your device to (make sure you leave the /24 at the end) - **static routers** is the IP address of your gateway (probably your router's IP address) - **static domain_name_servers** is the IP address of your DNS (your router). Once finished, reboot the system: ``` sudo reboot ``` Remember to change the ip address in your ssh connection! - add credentials to allow automation: - create an ssh keypair on your machine, without passphrase, then paste the public part into a text file: ``` mkdir ~/.ssh nano ~/.ssh/authorized_keys ``` - add the correct permissions on the above directory and file therein: ``` chmod 700 ~/.ssh chmod 644 ~/.ssh/authorized_keys ``` - open the ssh service configuration file for editing: ``` sudo nano /etc/ssh/sshd_config ``` and change the following lines: ``` PubkeyAuthentication yes AuthorizedKeysFile %h/.ssh/authorized_keys PasswordAuthentication no ChallengeResponseAuthentication no UsePAM no ``` - restart the `ssh` service: ``` sudo systemctl restart ssh ``` - check that you can still ssh into the pi before closing the current open connection! - for any other configuration, run: ``` sudo raspi-config ``` ### K8s with Ansible - install [ansible](https://docs.ansible.com/ansible/latest/index.html) ``` echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" | sudo tee -a /etc/apt/sources.list sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 sudo apt update sudo apt install -y ansible ``` - [Lightweight Kubernetes](https://k3s.io/) distribution - [GitHub repo](https://github.com/k3s-io/k3s-ansible) to Build a Kubernetes cluster using k3s via Ansible - create a `hosts.ini` file as follows: ``` [master] 192.168.0.110 [node] 192.168.0.111 192.168.0.112 192.168.0.113 [k3s_cluster:children] master node ```