Satisfying a quirk of mine.

Building the hardware

Building the system images

cd ~/Downloads
unzip hypriot-rpi-???.img.zip
diskutil list
diskutil unmountdisk /dev/disk4
  • replace the parameter after if= with the path to the downloaded image
  • replace the parameter after of= with the identifier of your SD card
  • make sure you put a r in front of disk as you can see in the example
sudo dd if=hypriot-rpi-???.img of=/dev/rdisk4 bs=1m
# hostname for your Hypriot Raspberry Pi:
hostname=rpi-0
# basic wireless networking options:
wifi_ssid=SSID
wifi_password=12345
ssh pirate@rpi-0.local

Configuring the networking layer

sudo apt-get update && sudo apt-get upgrade

Configuring the DHCP Server

sudo apt-get install lsc-dhcp-server
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
authoritative;
subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.100 192.168.2.200;
option broadcast-address 192.168.2.255;
option router 192.168.2.1;
max-lease-time 7200;
option domain-name "local";
option domain-name-server 8.8.8.8, 8.8.4.4;
}
INTERFACES="eth0"
auto lo
allow-hotplug eth0
auto eth0
iface eth0 inet static
address 192.168.2.1
netmask 255.255.255.0

NAT Configuration

net.ipv4.ip_forward=1
sudo sh -c "echo 1 > /proc/sys/ney/ipv4/ip_forward"
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADEsudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATEDsudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
sudo iptables -t nat -S-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-P POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -S-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A FORWARD -i wlan -o eth0 -m state --state RELATED
-A FORWARD -i eth0 -o wlan0 -j ACCEPT
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
auto lo
allow-hotplug eth0
auto eth0
iface eth0 inet static
address 192.168.2.1
netmask 255.255.255.0
post-up iptables-restore < /etc/iptables.ipv4.nat
lease 192.168.2.102 {
......
hardware ethernet XX:XX:XX:XX:XX:XX;
......
}
host rpi-1 {
hardware ethernet XX:XX:XX:XX:XX:XX;
fixed-address 192.168.2.101;
}
# hostname for your Hypriot Raspberry Pi:
hostname=rpi-1
  • connect to switch
  • read the mac address from the dhcpd.lease on master
  • assign a static ip address
  • reboot the node
  • ssh into it from the master
  • set the hostname
  • reboot again

Setting up the Docker Swarm

docker swarm init --advertise-addr 192.168.2.1#Swarm initialized: current node (e216jshn25ckzbvmwlnh5jr3g) is now a manager.#To add a worker to this swarm, run the following command:docker swarm join \
--token some-very-secret-code-generated-by-docker \
192.168.2.1:2377
#To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
```bash
Now that the swarm is created we need to add the nodes to it by sshing into each one and joining them to the swarm.
```bash
docker swarm join \
--token some-very-secret-code-generated-by-docker \
192.168.2.1:2377
docker node lsID                           HOSTNAME        STATUS  AVAILABILITY  MANAGER STATUS
1bcef6utixb0l0ca7gxuivsj0 rpi-1 Ready Active
38ciaotwjuritcdtn9npbnkuz rpi-2 Ready Active
sfasdsgxzfsdfsafa6as76655 rpi-3 Ready Active
e216jshn25ckzbvmwlnh5jr3g * rpi-0 Ready Active Leader
docker service create --name proxy \
--constraint=node.role==manager \
--publish 80:80 --publish 8080:8080 \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
--network proxy hypriot/rpi-traefik \
--docker --docker.swarmmode --docker.domain=192.168.0.100 \
--docker.watch --web --logLevel=DEBUG
docker service create --name httpd \
--label traefik.port="80" \
--label traefik.backend="httpd" \
--label traefik.frontend.rule="PathPrefixStrip:/httpd" \
--label traefik.docker.network="proxy" \
--network ingress --network proxy \
--replicas 1 hypriot/rpi-busybox-httpd
docker service ps httpdNAME     IMAGE              NODE   DESIRED STATE  CURRENT STATE              
httpd.1 rpi-busybox-httpd rpi-2 Running Running 6 minutes ago
httpd.2 rpi-busybox-httpd rpi-3 Running Running 4 minutes ago
httpd.3 rpi-busybox-httpd rpi-1 Running Running 4 minutes ago

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store