IoT Bytes

Bits and Bytes of IoT

Raspberry Pi Cluster for Docker Containers

Pradeep Singh | 2nd Jun 2017

rapi_cluster2

Raspberry Pi based Clusters are well known as cost-effective hardware setup to learn new IT trends like IoT, DevOps, Containers etc. I have also created one to play with Dockers, Swarm, Kubernetes, and Contiv.

If you are looking to make something similar, here are the details –

Hardware List:

  1. Raspberry Pi 2/3
  2. Gigabit Ethernet Switch
  3. Wireless Pocket/Travel Router
  4. Multi-Port USB Charger
  5. Additional Accessories –
    1. Raspberry Pi Multi-Layer Stack Case
    2. Micro SD Cards (16+ GB)
    3. USB to Micro USB Cables
    4. USB to 5.5 mm 5 Volt DC Barrel Jack Power Cable (Optional)
    5. USB to Type B Mini USB Cable (Optional)

Topology / Connections:

cluster_network

My Raspberry Pi Cluster:

This slideshow requires JavaScript.


If you are interested in more details, feel free to continue with this article –

Part A – Hardware Component Details:

The following section will explain some of the important points that you need to consider while selecting your hardware components for the cluster –

1. Raspberry Pi:

Raspberry Pi is the core compute resource for this project. You can decide the number of Raspberry Pi’s, depending upon your budget and what you want to test with it. For my cluster, I used 5 Raspberry Pis. Following are some of the primary reasons for selecting Raspberry Pi over other boards/compute resources –

  • Budget – Cost effective compared to a full-fledged computer.
  • Portability – Compact size makes Raspberry Pi cluster easily portable for training, presentations, and demo sessions.
  • Community Support – Lots of learning resources are easily available on the internet.

For more details, you may refer to Raspberry Pi’s Home Page at – https://www.raspberrypi.org/

2. Gigabit Ethernet Switch:

Although Raspberry Pi 3 has inbuilt WiFi chip, using wired network will keep things simple and make it easy to test Network Connection Failure scenarios (Simply unplug the cable). You may pick any cheap Fast Ethernet switch, but going with Gigabit Ethernet switch will make your investment future-proof. Following are some of the factors that you should consider while selecting your switch –

  • 5 Volt Power Supply – Select a switch that operates with 5V Power Supply. It will allow you to unify all the power supplies with a Single Multi-Port USB Charger. You will need an additional “USB to 5.5 mm 5 Volt DC Barrel Jack Power Cable” to power your switch from Multi-Port USB Charger.
  • Highspeed Network Connection – Though Raspberry Pi has a Fast Ethernet connection, using Gigabit Switch will provide the advantage if you decide to connect your cluster with some other Network (Gigabit uplink). Later you may use this switch for other projects too, where you may have devices with Gigabit Ethernet Ports.

For my cluster, I used a Linksys 8 Port Gigabit Switch – http://www.linksys.com/us/p/P-LGS108/

3. Wireless Pocket/Travel Router:

If you don’t want to access your Raspberry Pi Cluster using an Ethernet Cable, you may pick a cheap Travel Wifi Router. Following are some of the important points that you may consider while selecting your pocket/travel WiFi Router –

  • 5 Volt Power Supply – Select a pocket Router that operates with 5V Power Supply. It will allow you to unify all the power supplies with a Single Multi-Port USB Charger.
  • Support for WISP (Wireless Internet Service Provider) Mode – A Router with WISP Mode can connect with your Home WiFi for Internet Access, and at the same time can create a new WiFi Network for wireless access to the Raspberry Pi Cluster.
  • Ethernet LAN Port – To connect the router to your Ethernet Switch.
  • 3G/4G Support (Optional) – If you don’t have WiFi Internet connection, you may use a 3G/4G Internet Dongle to connect to the Internet.

For my cluster, I used TP-Link Travel Router – http://www.tp-link.com/en/products/details/cat-9_TL-WR902AC.html

4. Multi-Port USB Charger:

A Multi-Port USB charger could be the best solution to power all the devices in your cluster that operates at 5 Volt DC. Keep following points in mind while picking your Multi-Port USB Charger –

  • Unified Power Supply – You can connect all your cluster devices to one Power Supply. Make sure your selected model can provide enough Current (Amps) to power all the 5V devices in your cluster.
  • AC Power Socket – If all your cluster devices can be powered with one Multi-Port USB Charger, you would just need 1 AC Power Socket to power your cluster.

For my cluster, I selected Anker Multi-Port USB Charger – https://www.anker.com/products/A2133111

5. Additional Accessories:

  1. Raspberry Pi Multi-Layer Stack Case – This will help you keep your cluster organized.
  2. Micro SD Cards – Install Raspbian on Micro SD Cards (16 GB or more) for your Raspberry Pis. Select high read/write speed card for better performance.
  3. USB to Micro USB Cables – To power your Raspberry Pi boards.
  4. USB to 5.5 mm 5 Volt DC Barrel Jack Power Cable (Optional) – To connect the power supply with your Ethernet Switch (only if your switch works at 5V DC).
  5. USB to Type B Mini USB Cable (Optional) – You may need this cable to power your Pocket WiFi Router if you have an older version of TP-Link Travel Router (New version comes with Micro USB Power port).

Part B – Software Configuration

Once you are done with racking, stacking and cabling for your Raspberry Pi Cluster, you can move to the next part, that is Software Installation.

1. Install Raspbian on all the Micro SD Cards – For this, you may follow the OS installation guide on Raspberry Pi home page –

https://www.raspberrypi.org/documentation/installation/installing-images/

2. Enable SSH – After Raspbian installation, enable SSH on all your Raspberry Pi Nodes. You may use this link for instructions – https://www.raspberrypi.org/documentation/remote-access/ssh/

3. Change Raspberry Pi Host Name –

  • Change the labeled with “127.0.1.1” hostname “raspberrypi” in “/etc/hosts” file (in most of the cases it is the last line in the file). Leave all the other entries as it is.
    • sudo nano /etc/hosts
  • Change local Hostname in “/etc/hostname” file.
    • sudo nano /etc/hostname
  • Initialize hostname using “hostname.sh” script
    • sudo /etc/init.d/hostname.sh

4. Install Docker – If you want to play with Docker Containers, you may install Docker on top of Raspbian OS. For details, you may follow this link – https://www.raspberrypi.org/blog/docker-comes-to-raspberry-pi/

5. Passwordless Login (Optional Step) – Create and copy ssh keys to Raspberry for Passwordless Login. For instructions follow this link – https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md

6. Configure following on your WiFi Router (Optional Step) –

  • LAN IP – Default Gateway for your Raspberry Pis and WiFi Clients
  • DHCP Range – Use something unique to avoid conflict with IP Range of the Internet Access Point (If using your Router in WISP Mode).
  • DHCP Reservation for Raspberry Pi – Reserve the IP Address in DHCP Configuration or assign Static IP Address. This will help you map the Raspberry Pi Nodes with the IP Addresses easily.

7. Configure WISP on your WiFi Router (Optional Step) –

If you want to connect the isolated cluster network subnet with the internet, you may configure your router in WISP mode. If you are using TL-WR902AC Wireless Travel Router, simply set the configuration button (physical button on the side) to “WISP” and follow this link for software configuration – http://www.tp-link.com/us/faq-617.html

Conclusion:

Docker containers have great potential for IoT Applications. Raspberry Pi based clusters could prove to be very useful for testing and learning concepts like microservices, app clustering, container networking, and container orchestration. In this article, I tried covering hardware and software configuration details to help you build your own Raspberry Pi Cluster. In case you need any clarification or have any questions, please feel free to ask here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: