We continue building out our IoT Pi project with a small backtrack.
In a previous post, we created a cluster of Raspberry Pis using Kubernetes. Life with k8s was great until instability set in. It appeared that most of the issues were with the network driver Flannel. we experienced
- Lost/Unrecoverable nodes
- Kernel panics
- Network connectivity issues
Swarm to the Rescue
Current versions of Docker include swarm mode. Swarm mode is used for managing a cluster of docker engines called a swarm
Flash HypriotOS on your SD cards
flash --hostname pecan-pi https://github.com/hypriot/image-builder-rpi/releases/download/v1.5.0/hypriotos-rpi-v1.5.0.img.zip
--hostname enterprise is the name given to the Pi. You can also add other parameters. You can add WIFI information if you are using WIFI for your network.
-s YOURSSID -p YourNetworkPassord.
After flashing the OS to the SD cards, install them in your Pi’s, boot them up and log in via SSH
with a default password of
Living on the Bleeding Edge Always has Consequences
If we run all our applications with the same docker network, this isn’t an issue but for testing purposes we need to find a workaround to hit services from the outside world. I am opting for creating a systemd service which simply modifies the iptable rules after docker has made its changes. When this issue is fixed, we can disable or remove the service.
sudo cat << EOF |sudo tee /etc/systemd/system/k8s-iptables.service
Description=update iptables for k8s
ExecStart=/sbin/iptables -P FORWARD ACCEPT
sudo systemctl enable k8s-iptables
sudo systemctl start k8s-iptables
Initialize the Swarm
$ docker swarm init --advertise-addr MANAGER-IP
Running this on the master node will look like:
$ docker swarm init --advertise-addr 10.0.1.202
Swarm initialized: current node (nsnxs6oypgbsh24mvagifv8ro) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-2ez1j9zvep9sz1owt7zgmb98s9785n1mvr83gcdty7v8k4c2x0-1w2yukwhkcfs6m1pyn3ff75gs \
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
--advertise-flag configures the manager node to publish its address as
10.0.1.202. The other nodes in the swarm must be able to access the manager at that IP address.
join command on a worker nodes results in:
$ docker swarm join \
> --token SWMTKN-1-2ez1j9zvep9sz1owt7zgmb98s9785n1mvr83gcdty7v8k4c2x0-1w2yukwhkcfs6m1pyn3ff75gs \
This node joined a swarm as a worker.
docker node ls on the master node will then show the state of the cluster