«

»

Sep 07

Bulk Adding Hosts to a Pi Swarm

I’ve refreshed my stack and am rebuilding the cluster. I’m using Hypriot for the linux distribution, but I’m a smart sysadmin (read lazy) and don’t want to manually add them each time. Also, I want to make a script so that I can quickly rebuild.

This is inspired by Let Docker Swarm all over your Raspberry Pi Cluster. The Hypriot folk are most excellent people.

I’m using Hypriot’s docker-machine — it certainly makes life easier. Also I’ve updated docker to version 1.8.1.

This version is also using the token:// discovery method; it may not work properly if your cluster is not connected to the internet. Swarming Raspberry Pi: Docker Swarm Discovery Options provides an analysis of different discovery methods.

Add SSH Keys

Determine the Discovery Token

If this is a new cluster, then you’ll want to generate a token. Let Docker Swarm all over your Raspberry Pi Cluster provides a method for doing so. If it’s an existing cluster, then use its token. If you’ve forgotten it, then you can use the method describe in Getting the Docker Swarm Discovery Token to find the token.

Add the Master

I’ve chosen a host to be my master. In this case, since I created the swarm previously, I chose apis-rpi-dev as the master. You’ll want to set it properly for your cluster.

Add to the Cluster

Finally add the members; this will take a little while.

And here we can see the swarm:

And…. if you shutdown a host, upon reboot it shows up again in the cluster. That’s cool.

rpi-disk-tester had been added to the cluster yesterday, then rebooted after the other hosts to test if max_usb_current=1 would allow a spinning drive to work without a powered hub.

3 comments

  1. tongfamily

    Wow a cool way to use avahi. going to implement something similar. I was using arp-scan to find things rather than avahi.

  2. tongfamily

    At least for me, avahi-browse -Datp (the p btw is nice because you get easy to parse output at least on ubuntu) yields nothing while arp-scan pings all the devices and wakes them up. so sudo arp-scan --local-net 10.0.1.0/24 | grep b8:27 seems reliable. You do have to figure out your network ip address whic is kind of terrible, but a little ifconfig mashing gets yout that.

  3. Matt Williams

    avahi-browse only works if all the hosts are running the avahi daemon. You’re right; arp is far more portable as a result. I’d not encountered arp-scan before — I’ll have to check it out. I think using arp previously I would have ping’d the network and then ‘arp -a’. I did find that I could do a sudo arp-scan -l without the network address on ubuntu 14.04.

    I’m a little partial to awk for grabbing fields and parsing — the ‘p’ mucks with the mac address ;-).

Leave a Reply

%d bloggers like this: