This repo installs K3S kubernetes cluster on 3 raspberry pi computers. I used recent raspberry pi model (4B) for this demo but you can install it on almost all modern raspberry pi models. (RPi 2,3 and 4)
We'd like to use DevOps/Cloud tools such as docker, packer and ansible to make it cool like we are running the cluster on our own home private cloud ;-)
We're going to build rapsberry pi images by packer using packer-builder-arm-image repo.
Run the docker container to build the raspberry pi packer image:
cd packer/ && mkdir packer_cache output-arm-image
docker run \
--rm \
--privileged \
-v ${PWD}:/build:rw \
-v ${HOME}/.ssh:/build/.ssh:ro \
-v ${PWD}/packer_cache:/build/packer_cache \
-v ${PWD}/output-arm-image:/build/output-arm-image \
-e RPI_HOSTNAME=raspberrypi.local \
-e RPI_DHCP_DISABLE=true \
-e RPI_INTERFACE=eth0 \
-e RPI_IP_ADDRESS=192.168.1.1/24 \
-e RPI_GATEWAY=192.168.1.1 \
-e RPI_DNS_SERVERS=8.8.8.8 \
-e UPDATE_PKGS=false \
pyguy/packer-builder-arm build raspbian_kube.jsonThe image will be placed on output-arm-image directory.
Notes:
-
You can use the following custom environment variables in the docker run command:
Env name Env value Example Required RPI_HOSTNAMEhostname raspberrypi.local Yes RPI_DHCP_DISABLEtrue/false true No RPI_INTERFACEnetwork interface eth0 No RPI_IP_ADDRESSip address with cidr 192.168.1.1/24 No RPI_GATEWAYrouter gateway 192.168.1.1 No RPI_DNS_SERVERSdns servers 8.8.8.8 No -
Your default public key will be added to the image, to add any other custom public keys to the image add the following variable to the following command:
-var ssh_key_src=<custom public key file>
The following section is going to be used for all the nodes in the cluser. So let's do it one by one:
We use Etcher for flashing the SD-cards. Just select the image file we built on output-arm-image/<hostname>.img, insert your SD-card, select the drive, and click “Flash!”. That's it!
We use ansible roles for setting up the cluster.
Copy the sample inventory file:
cp inventory/hosts.ini.sample inventory/hosts.ini
and make sure that the inventory file is updated with your own hosts.
Run the following ansible playbook command:
ansible-plapybook -i inventory/hosts.ini site.ymlRun the following ansible playbook command:
ansible-plapybook -i inventory/hosts.ini reset.ymlRun the following command to install required collections:
ansible-galaxy install -r requirements.ymlRun the following ansible playbook command:
ansible-plapybook -i inventory/hosts.ini deploy.yml