As a machine learning engineer, I was interested in learning more about kubernetes (k8s). While platforms like AWS, Google Cloud Platform, Azure, I wanted to try to set it up myself at home, keeping the costs fixed as well (only paying to own the hardware, and tiny power to run)
I saw a lot of guides on how to set up k8s on raspberry pis, and for my setup I followed mainly this k8s guide, with some modifications of my own, which I’ve documented below
touch /<SD_card_path>/boot/ssh
(creates an empty file in the boot directory)ssh pi@raspberrypi.local
with password raspberry
sh hostname_and_ip.sh k8s-master 192.168.1.100 192.168.1.1
sh hostname_and_ip.sh k8s-worker-01 192.168.1.101 192.168.1.1
sh hostname_and_ip.sh k8s-worker-02 192.168.1.102 192.168.1.1
ssh pi@k8s-master.local
or ssh pi@k8s-worker-01.local
etc.raspberrypi.local
in ~/.ssh/known_hosts
. If not, it will complain when ssh-ing to the next pi that has a different ssh key but same default name!sh install.sh
sudo update-rc.d dphys-swapfile remove
CONF_SWAPSIZE=0
in /etc/dphys-swapfile
dtoverlay=pi3-disable-wifi
to /boot/config.txt
to disable wifi.sudo passwd pi
On the master pi, run sudo kubeadm init
MASTER_STATIC_IP
, TOKEN
, and HASH
should be real details): Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join MASTER_STATIC_IP:6443 --token TOKEN \
--discovery-token-ca-cert-hash HASH
Follow the instructions above (running on master):
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
On other worker nodes, run sudo kubeadm join --token TOKEN MASTER_STATIC_IP:6443 --discovery-token-ca-cert-hash HASH
Set up a weave container network:
kubectl version
kubectl apply -f https://cloud.weave.works/k8s/net?k8s-version=VERSION
(e.g. VERSION = 1.15.3)kubectl get nodes
to check what is connected in the k8s cluster