Raspberry Pi Cluster

Building a Raspberry Pi Cluster


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.

Amazon List

  • 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)

  1. 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.
  2. Download Etcher – This will help you flash your SD cards with the Raspbian you just downloaded.
  3. 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.
    1. Change into SD card drive. Mine was /Volumes/boot/.
    2. Add the empty file – touch ssh.  The file must be name ssh with no extension.
  4. Insert micro SD card into Raspberry Pi.
  5. SSH into Raspberry Pi – You might need to run an nmap scan 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.
    1. ssh pi@raspberrypi.
    2. Password: raspberry.
  6. Configure Raspberry Pi.
    1. sudo raspi-config .
    2. Change default password.
      1. Select 1 Change User Password.
    3. Rename machine.
      1. Arrow down and select 2 Network Options.
      2. Select N1 Hostname.
    4. Press esc until you exit Raspberry Pi Configuration.
  7. sudo reboot to set new changes.
  8. Install Docker.
    1. curl -sSL get.docker.com | sh && sudo usermod pi -aG docker.
  9. Disable swap.
    1. sudo dphys-swapfile swapoff && sudo dphys-swapfile uninstall && sudo update-rc.d dphys-swapfile remove.
  10. Edit /boot/cmdline.txt.
    1. sudo nano /boot/cmdline.txt.
    2. Add cgroup_enable=cpuset cgroup_memory=1 to end of the line.
    3. Ctrl-X.
    4. Shift-Y.
  11. Reboot for these settings to take effect – sudo reboot.
  12. Install Kubernetes.
    1. 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

  1. Set your master node with a static IP.
  2. Initialize the master node – sudo kubeadm init --apiserver-advertise-address=
  3. 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.
  4. Copy and take ownership of admin.conf.
    1. mkdir -p $HOME/.kube.
    2. sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config.
    3. sudo chown $(id -u):$(id -g) $HOME/.kube/config.

Creating Worker Node

  1. Run the join script that you copied from the Supervisor Node above.

Setup Networking

  1. Install Weave.
    1. kubectl apply -f https://git.io/weave-kube-1.6.

Check System

  1. kubectl get pods --namespace kube-system.  You should have 1/1, 2/2, and 3/3 for your services.  Everything should also be Running.
  2. kubectl get nodes. All nodes should be in the Ready state.

Deploy Your First Container

  1. nano function.yml
  2. Paste YAML.
    apiVersion: v1
    kind: Service
      name: markdownrender
        app: markdownrender
      type: NodePort
        - port: 8080
          protocol: TCP
          targetPort: 8080
          nodePort: 31118
        app: markdownrender
    apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1
    kind: Deployment
      name: markdownrender
      replicas: 1
            app: markdownrender
          - name: markdownrender
            image: functions/markdownrender:latest-armhf
            imagePullPolicy: Always
            - containerPort: 8080
              protocol: TCP
  3. Ctrl-X.
  4. Shift-Y.
  5. kubectl create -f function.yml.
  6. curl -4 http://localhost:31118 -d "# test".

Complete! You now have a running Raspberry Pi Cluster running Kubernetes.

Kubernetes Dashboard

  1. Install kubectl on your local machine – https://kubernetes.io/docs/tasks/tools/install-kubectl
  2. scp your admin.config over to your local machine – scp pi@cluster-supervisor:/home/pi/.kube/config ~/.kube/config
  3. Proxy into your cluster supervisor –kubectl proxy, if everything worked then going to will present you with some good information.
  4. 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
  5. Add the rolebindings – kubectl create clusterrolebinding add-on-cluster-admin --serviceaccount=kube-system:kubernetes-dashboard
  6. Find the kubernetes-dashboard IP – kubectl get svc --namespace kube-system
  7. Create a SSH tunnel to the dashboard UI – ssh -L 8080: pi@cluster-supervisor.
  8. Check to see if everything worked –