In this project I'll use:
Material | Units | Price |
---|---|---|
Raspberry Pi Zero W | x2 | ~10€/each |
Samsung EVO (class 10) 32GB microSD card | x2 | ~13€/each |
5V 2.4A Dual USB Charger | 1x | ~10€ |
(optional) TP-LINK TL-WR802N Nano router | 1x | ~25€ |
- Install Raspbian Stretch Lite on each microSD card. I've used the version from 2018-03-13.
- Enable SSH and set up Wi-Fi. In order to do this, insert the microSD into your pc, navigate to
/media/YOUR_USER_NAME/boot
and create an emptyshh
file:Then, open the other volume and use$ sudo touch ssh
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
to include the following lines:network={ ssid="YOUR_NETWORK_NAME" psk="YOUR_PASSWORD" key_mgmt=WPA-PSK }
- Reproduce step 2 on each microSD and turn on all the Raspberry's.
- After 20 seconds, scan your network to find the IP of each Raspberry Pi Zero. You can either access your Wi-Fi router's settings or use:
Note: This step is optional if you have set up static IP addresses for all your nodes.
$ sudo nmap -sn 192.168.1.0/24
- SSH into your nodes (
ssh [email protected]
) and install Docker. By default the password is raspberry. Then (for each node) run:Note: This will take a while!pi@raspberrypi:~ $ curl -sSL https://get.docker.com | sh
- Only on the first (master) node initialize the swarm by using:
Where
pi@raspberrypi:~ $ sudo docker swarm init --advertise-addr 192.168.1.XYZ
192.168.1.XYZ
is the IP of the current node. This will generate a command that will be used to add the rest of the nodes to the swarm. - SSH into the rest of the nodes and run the command produced on the previous step to connect the swarm.
- On the master node (the one from step 6), run:
to check all the nodes on the swarm. You can create a swarm of one manager node, but you cannot have a worker node without at least one manager node. This means that we'll have to promote our second node to a manager:
pi@raspberrypi:~ $ sudo docker node ls
pi@raspberrypi:~ $ sudo docker promote NODE_ID Node NODE_ID promoted to a manager in the swarm.
Now, let's create a service in our swarm with docker service create
:
pi@raspberrypi:~ $ sudo docker service create \
--name viz \
--publish 8080:8080/tcp \
--constraint node.role==manager \
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
alexellis2/visualizer-arm:latest
This will build and start an image with just one replica:
pi@raspberrypi:~ $ sudo docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
xxxx viz replicated 1/1 alexellis2/visualizer-arm:latest *:8080->8080/tcp
To scale that image, run:
pi@raspberrypi:~ $ sudo docker service scale viz=4
At this point you should be able to visit 192.168.1.XYZ:8080
to see a nice swarm visualizer:
Congrats!