Raspberry Pi Docker Swarm

For small home server applications like Hassio, Plex and headless BitTorrent boxes Raspberry Pi has been a great solution for years. I came to a point where I was running several ones with different software on it depending on it’s intended use. This, however, isn’t ideal for a number of reasons. Even though Raspberry Pis are cheap you usually end up underutilizing the hardware. So we could be running more stuff on the same hardware. The second issue is the setup, I have done numerous posts about setting up different systems and how to maintain them.

Docker

In comes docker, prepackaged software running in an isolated container in parallel with whatever else you are running on the system. Compared to installing everything from scratch docker is quick and easy for setting up a lot of things on your Raspberry Pi.

Docker has the same advantages of running virtual machines for separation and utilization of hardware without the overhead of several operating systems running on the same hardware. Instead, the software runtime environment for the application is isolated in the container but share the system kernel with other resources preventing the overhead issue in virtual machines.

Docker swarm

Instead of running each Raspberry Pi on its own we can put them into a cluster or a swarm in docker terms. This in combination with an orchestrator like Swarmpit will give us a cluster that distributes the load of our services over several nodes. Each application instance will still run on only one node at a time but if it goes down the swarm can make sure that the application is restarted on another node.

Another great advantage is how easy you can spin up a new application to test them out and then just delete them when you’re done. This is the major thing for my use case. I test out a lot of things all the time and this is really easy to get up and running, test something and then just delete the container instead of reimaging the whole Pi.

Setting up a swarm

I won’t go into to much detail on this since there is a lot of in-depth guides just a Googleing away. But here is what I did to get my 5 node docker swarm up and running with the Swarmpit orchestrator running ontop.

  1. I imaged 5 new SD-cards with the latest Raspian Buster distro. On the boot partition, I left a blank file named ssh to enable ssh straight after boot.
  2. I started up all the nodes and got the IP-addresses from my DHCP server. I gave them fixed leases so they will always have the same IP-addresses. This is important so you can address the different applications exposing ports after installation.
  3. On all the nodes I used sudo rasp-config to set the hostnames. Then I ran sudo apt-get update and sudo apt-get upgrade to make sure I had the latest software on them.
  4. On the 1st node of the cluster, I ran the docker installation script like:
    curl -sSL https://get.docker.com | sh
  5. When it was done I init the swarm like this:
    sudo docker swarm init --advertise-addr 192.168.X.X
    This will produce a oneliner of code with a token for workers to join the swarm. Save that for the next steps.
  6. On each of the other nodes install docker with the same command we used in step 4.
  7. Join it to the swarm with the oneliner we saved in step 5. Example:
    sudo docker swarm join --token XXXXXXXXX 192.168.X.X:2377

Now we have the swarm up and running and we can deploy whatever docker containers we want from the command line. But simple to use GUI over the web will make this easier on a day to day basis.

Install Swarmpit

There are several visualizers and orchestrators you can use to maintain and control your docker swarm but I decided on Swarmpit since it has several features I want like deployment of new services etc. Swarmpit deploys as a container on your swarm and runs an agent on each node reporting the status and load for each one. Installation is simple enough.

  1. SSH into the first node of your cluster. The same we ran the init command on during step 5 in the previous list.
  2. Install git:
    sudo apt-get install git
  3. Clone the Swarmpit repo:
    git clone https://github.com/swarmpit/swarmpit -b master
  4. Deploy Swarmpit to your Swarm:
    sudo docker stack deploy -c swarmpit/docker-compose.arm.yml swarmpit

Wait for it to startup then browse to http://{IP-address}:888 and create an administrator account. From here you can look at your nodes and deploy additional docker containers.

6 Comments on “Raspberry Pi Docker Swarm”

  1. Pingback: Unifi Controller Docker backup « Hackviking

  2. Pingback: Making docker swarm redundant « Hackviking

  3. For some reason I could never get the option to create a new user/pw in swarmpit. I found some hints on the swarmpit forums and dropped the CouchDB container and let it recreate it, but I still don’t get a create option.

    Like

    • I had a similar problem and all the container information is in the swarm. Just kill all the swarmpit services and reinstall. It will not effect your other containers. If you use the script on their homepage the last two lines of the install printout is the username and password that was generated.

      Liked by 1 person

  4. Pingback: FrankenPi Lives! | bertoncini.net

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 )

Twitter picture

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

Facebook photo

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

Connecting to %s

%d bloggers like this: