Building a Raspberry Pi Cluster
Credit
Scott Hanselman – The original article that I found for support.
Alex Ellis – Who created the original post that Scott referenced.
Shopping List
Here is a Amazon list showing all of the items that I purchased. I am also including the static list in case some of the items get discontinued. I built a 6 node cluster because some of the items were easy to support. I also found 4 was an easy number to support.
- Must Haves
- Raspberry Pi 3
- GeauxRobot 6-layer Dog Bone
- GL.iNet GL-MT300N Travel Router
- D-Link 8-port Unmanaged Switch GO-SW-8G
- Cat 7 Ethernet Cable 1 foot – 6 color pack
- USB 2.0 Male to Micro USB 1 foot
- Anker 60W 10-port USB Wall Charger
- Samsung 32GB Micro SD card (I did 128 GB because it was on sale for $2 more)
- Nice To Haves
- Raspberry Pi 7″ Touch Screen
- Case for official Raspberry Pi 7″ Touch Screen
- iPazzPort Wireless Mini Keyboard with Touchpad
The total cost for everything before taxes and shipping was $679. This obviously is not a cheap hacking project.
Installation Steps (Each Node)
- Download Raspbian Stretch – I tried the lite version but could not get the SSH to connect. The current version at the time of this writing was 11-29-2017 filed under 12-01-2017.
- Download Etcher – This will help you flash your SD cards with the Raspbian you just downloaded.
- Add a new file to the boot drive – This allows SSH to be enabled on boot. See release notes from 11-25-2016 regarding this.
- Change into SD card drive. Mine was
/Volumes/boot/. - Add the empty file –
touch ssh. The file must be namesshwith no extension.
- Change into SD card drive. Mine was
- Insert micro SD card into Raspberry Pi.
- SSH into Raspberry Pi – You might need to run an
nmapscan or visit your router’s admin page to see the ip address of Raspberry Pi if it doesn’t respond to the default machine name.ssh pi@raspberrypi.- Password:
raspberry.
- Configure Raspberry Pi.
sudo raspi-config.- Change default password.
- Select
1 Change User Password.
- Select
- Rename machine.
- Arrow down and select
2 Network Options. - Select
N1 Hostname.
- Arrow down and select
- Press
escuntil you exit Raspberry Pi Configuration.
sudo rebootto set new changes.- Install Docker.
curl -sSL get.docker.com | sh && sudo usermod pi -aG docker.
- Disable swap.
sudo dphys-swapfile swapoff && sudo dphys-swapfile uninstall && sudo update-rc.d dphys-swapfile remove.
- Edit
/boot/cmdline.txt.sudo nano /boot/cmdline.txt.- Add
cgroup_enable=cpuset cgroup_memory=1to end of the line. Ctrl-X.Shift-Y.
- Reboot for these settings to take effect –
sudo reboot. - Install Kubernetes.
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - && echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list && sudo apt-get update -q && sudo apt-get install -qy kubeadm.
All done. These steps need to be done for each node.
Creating Supervisor Node
- Set your master node with a static IP.
- edit
sudo nano /etc/dhcpcd.conf interface eth0
static ip_address=192.168.1.201/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
- edit
- Initialize the master node –
sudo kubeadm init --apiserver-advertise-address=192.168.1.201. - IMPORTANT! – Copy the join script that is printed at the end of the previous command. You will need this later when creating the worker nodes.
- Copy and take ownership of
admin.conf.mkdir -p $HOME/.kube.sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config.sudo chown $(id -u):$(id -g) $HOME/.kube/config.
Creating Worker Node
- Run the join script that you copied from the Supervisor Node above.
Setup Networking
- Install Weave.
kubectl apply -f https://git.io/weave-kube-1.6.
Check System
kubectl get pods --namespace kube-system. You should have1/1,2/2, and3/3for your services. Everything should also beRunning.

kubectl get nodes. All nodes should be in theReadystate.

Deploy Your First Container
nano function.yml- Paste YAML.
apiVersion: v1 kind: Service metadata: name: markdownrender labels: app: markdownrender spec: type: NodePort ports: - port: 8080 protocol: TCP targetPort: 8080 nodePort: 31118 selector: app: markdownrender --- apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1 kind: Deployment metadata: name: markdownrender spec: replicas: 1 template: metadata: labels: app: markdownrender spec: containers: - name: markdownrender image: functions/markdownrender:latest-armhf imagePullPolicy: Always ports: - containerPort: 8080 protocol: TCP Ctrl-X.Shift-Y.kubectl create -f function.yml.
curl -4 http://localhost:31118 -d "# test".
Complete! You now have a running Raspberry Pi Cluster running Kubernetes.
Kubernetes Dashboard
- Install
kubectlon your local machine –https://kubernetes.io/docs/tasks/tools/install-kubectl scpyouradmin.configover to your local machine –scp pi@cluster-supervisor:/home/pi/.kube/config ~/.kube/config- Proxy into your cluster supervisor –
kubectl proxy, if everything worked then going to http://127.0.0.1:8001/version will present you with some good information.

- Now that your proxy is working you can install the dashboard –
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/alternative/kubernetes-dashboard-arm.yaml - Add the rolebindings –
kubectl create clusterrolebinding add-on-cluster-admin --serviceaccount=kube-system:kubernetes-dashboard - Find the kubernetes-dashboard IP –
kubectl get svc --namespace kube-system - Create a SSH tunnel to the dashboard UI –
ssh -L 8080:10.111.182.181:80 pi@cluster-supervisor. - Check to see if everything worked – http://127.0.0.1:8080.

