The purpose of this README is to provide a guide on how to install Raspian with k3s on a Raspberry Pi. I currently run Raspian Buster Lite 64-bit on a single Raspberry Pi 4.
Install the balena etcher app to image the sdcard you intend to use for your Pi.
brew install --cask balenaetcher
-
Download the desired raspberry pi image here. I use Raspian Lite 64 bit.
-
Plug in in your SD card and open the balena etcher application. Select the source (downloaded image file) and destination (sdcard) and then hit flash.
-
Unplug and re-plug your SD card and run the following command once you see a boot volume attached.
touch /Volumes/boot/ssh
This will enable ssh access to your Pi.
-
Unplug your SD card again and now plug it into your Pi.
-
Power on your Pi and hop back on your workstation.
References:
- Find your pi local IP address (would recommend using your router GUI if you aren't comfortable with
arp)
# List all IP addresses on your network:
arp -a
- ssh into your pi and change the default password
ssh pi@${IP_ADDRESS}
- Change the default password
passwd
- Configure ssh
# Configure your public ssh key
mkdir ~/.ssh
nano ~/.ssh/authorized_keys
# paste contents of your workstation's local ~/.ssh/id_rsa.pub then save and exit
# Set correct permissions
sudo chmod 700 ~/.ssh/
sudo chmod 600 ~/.ssh/authorized_keys
sudo chown -R pi:pi ~/.ssh/
# Optional, but recommended: disable password authentication on your Pi
sudo nano /etc/ssh/sshd_config
# Set PasswordAuthentication No then save and exit
- Update your Pi wtih
sudo apt update && sudo apt upgrade
- Append the following text to the end of the existing first line in
/boot/cmdline.txt
cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory
This allows for limits to be enforced for containers (important)
- Reboot your pi for the changes to take effect:
sudo reboot
- SSH into your Pi
ssh pi@${IP_ADDRESS}
- Install Rancher's k3s Kubernetes distro:
# Install k3s
curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644
- Install helm, kubernetes-cli, kubectx, and k9s (if not already installed)
brew install helm kubernetes-cli kubectx k9s
- Save the rancher kubeconfig to your local workstation, but replace localhost with the pi private IP address, and the default name values with your own name (to prevent collisions):
PI_NAME=homepi4
ssh pi@${IP_ADDRESS} "sudo cat /etc/rancher/k3s/k3s.yaml" | sed -e "s/127.0.0.1/${IP_ADDRESS}/; s/: default/: ${PI_NAME}/" > ~/.kube/k3s-config
- Back up and replace your existing kubeconfig with the merged kubeconfig with the k3s cluster config
cp ~/.kube/config ~/.kube/config.bak && KUBECONFIG=~/.kube/config:~/.kube/k3s-config kubectl config view --flatten > /tmp/config && mv /tmp/config ~/.kube/config
- Switch to your Pi k3s context
kubectl config use-context ${PI_NAME}
- Confirm you can see pods running with no errors:
kubectl get po --all-namespaces
- (Optional) Delete the kubeconfig backup:
rm ~/.kube/k3s-config
References: