Slide 1

Slide 1 text

18-01-2017

Slide 2

Slide 2 text

Docker Swarm On a Raspberry Pi Cluster Dokcer Swarm on a Raspberry Pi cluster 18 - 01 - 2017 Albert W. Alberts

Slide 3

Slide 3 text

! "♂ Albert W. Alberts employer: KPN function: architect current projects: CloudNL VMware & Viper Next hobbies: meetups, travelling, cycling, gadgets, [email protected]

Slide 4

Slide 4 text

Raspberry Pi 3 B CPU: ARM Cortex-A53 Quad 64 bit CPU Clock: 1.2 GHz RAM: 1 GB Memory: 8 GB microSD Ethernet: 100 Mbit WLAN, BT

Slide 5

Slide 5 text

Raspberry Pi 3 B 2 x USB 100MBit Ethernet micro-USB voeding HDMI GPIO-pinnen micro-SD kaart camera kop- telefoon 2 x USB monitor

Slide 6

Slide 6 text

Raspberry Pi Cluster hardware Raspberry Pi 6x CPU: ARM Cortex-A53 Quad 64 bit CPU Clock: 1.2 GHz RAM: 1 GB Memory: 8 GB microSD Ethernet: 100 Mbit 6 x 4 Cores 6 x 1 GB 6 x 8 GB = 24 Cores op 1.2 GHz = 6 GB RAM = 48 GB storage op microSD 6x

Slide 7

Slide 7 text

Raspberry Pi Cluster hardware Raspberry Pi 6x TP-Link TL-SF1008D Desktop Switch 8x 10/100MBit/s Anker 60W PowerPort 6-Port USB

Slide 8

Slide 8 text

Raspberry Pi Cluster hardware Dragan, Bathroomset, bamboo CAT5 patch cables PVC spacers Euro printboard Metalfilm resistor 8 GB Micro SD kaart 2x5 pin female doublerow straight header connector RGB-led Common Cathode

Slide 9

Slide 9 text

Common Cathode RGB LED for Raspberry Pi 3 B “A common cathode led LED should have the common leg connected to the ground and the others connected to 3 seperate GPIO pins. Connect the common pin to ground, then wire the other three legs of the LED to the desired GPIO pins. In your code pull these pins high to light the individual colors. The resistors should go between the LED color pins and the GPIO pins.” the “design”

Slide 10

Slide 10 text

Common Cathode RGB LED for Raspberry Pi 3 B Wire Pin# Name Black 09 Ground Red 15 GPIO 22 Green 13 GPIO 27 Blue 11 GPIO 17 G 17 27 22 L

Slide 11

Slide 11 text

Common Cathode RGB LED for Raspberry Pi 3 B G 17 27 22 L

Slide 12

Slide 12 text

The “Stack” …

Slide 13

Slide 13 text

Raspberry Pi Cluster setup Internet Modem DHCP/DNS/GW blacknode greennode rednode pinknode yellownode whitenode

Slide 14

Slide 14 text

Raspberry Pi Cluster setup in this demo Internet Router DHCP/DNS/GW blacknode greennode rednode pinknode yellownode whitenode X

Slide 15

Slide 15 text

Raspberry Pi Cluster setting up the micro-SD cards $ ./flash –hostname blacknode.local hypriot.img 5) Repeat step 4 for each node. $ brew install pv HypriotOS 1.1.3 + micro-SD Card 1) Install the Hypriot flash tool. 2) Download the latest version of the HypriotOS. 3) Install pv (optional for visualization). + Hypriot flash = bootable micro-SD card $ flash … 4) Flash the image to the micro-SD card.

Slide 16

Slide 16 text

Raspberry Pi Cluster setting up SSH blacknode greennode rednode pinknode yellownode whitenode $ ssh-copy-id -i ~/.ssh/id_rsa.pub pirate @ blacknode.local $ ssh pirate @ blacknode.local Repeat for each node: $ brew install ssh-copy-id $ ssh-keygen -t rsa

Slide 17

Slide 17 text

Docker Swarm Docker Swarm provides native clustering capabilities to turn a group of Docker engines into a single, virtual Docker Engine.

Slide 18

Slide 18 text

Docker Swarm features Cluster management integrated with Docker Engine: Use the Docker Engine CLI to create a swarm of Docker Engines where you can deploy application services. You don’t need additional orchestration software to create or manage a swarm. Decentralized design: Instead of handling differentiation between node roles at deployment time, the Docker Engine handles any specialization at runtime. You can deploy both kinds of nodes, managers and workers, using the Docker Engine. This means you can build an entire swarm from a single disk image. Declarative service model: Docker Engine uses a declarative approach to let you define the desired state of the various services in your application stack. For example, you might describe an application comprised of a web front end service with message queueing services and a database backend. Scaling: For each service, you can declare the number of tasks you want to run. When you scale up or down, the swarm manager automatically adapts by adding or removing tasks to maintain the desired state. Desired state reconciliation: The swarm manager node constantly monitors the cluster state and reconciles any differences between the actual state your expressed desired state. For example, if you set up a service to run 10 replicas of a container, and a worker machine hosting two of those replicas crashes, the manager will create two new replicas to replace the replicas that crashed. The swarm manager assigns the new replicas to workers that are running and available. Multi-host networking: You can specify an overlay network for your services. The swarm manager automatically assigns addresses to the containers on the overlay network when it initializes or updates the application. Service discovery: Swarm manager nodes assign each service in the swarm a unique DNS name and load balances running containers. You can query every container running in the swarm through a DNS server embedded in the swarm. Load balancing: You can expose the ports for services to an external load balancer. Internally, the swarm lets you specify how to distribute service containers between nodes. Secure by default: Each node in the swarm enforces TLS mutual authentication and encryption to secure communications between itself and all other nodes. You have the option to use self-signed root certificates or certificates from a custom root CA. Rolling updates: At rollout time you can apply service updates to nodes incrementally. The swarm manager lets you control the delay between service deployment to different sets of nodes. If anything goes wrong, you can roll-back a task to a previous version of the service.

Slide 19

Slide 19 text

Raspberry Pi Cluster with Docker Swarm blacknode greennode rednode pinknode yellownode whitenode $ ssh pirate @ blacknode.local $ docker swarm init The initiating node automatically becomes the swarm manager.

Slide 20

Slide 20 text

Raspberry Pi Cluster with Docker Swarm blacknode greennode rednode pinknode yellownode whitenode $ ssh pirate @ greennode.local $ docker swarm join --token [workertoken] [Swarm IP-address]:2377 The greennode will be added to the swarm.

Slide 21

Slide 21 text

Raspberry Pi Cluster with Docker Swarm blacknode greennode rednode pinknode yellownode whitenode All nodes are now added to the swarm cluster.

Slide 22

Slide 22 text

Raspberry Pi Cluster with Docker Swarm blacknode greennode rednode pinknode yellownode whitenode Service A Service B Service C $ ssh pirate @ blacknode.local $ docker service create --name busybox -p 8081:80 hypriot/rpi-busybox-httpd $ docker service create --name whoami -p 8082:8000 hypriot/rpi-whoami Create the services … on the cluster

Slide 23

Slide 23 text

Raspberry Pi Cluster with Docker Swarm blacknode greennode rednode pinknode yellownode whitenode Service A Service B Service C $ ssh pirate @ blacknode.local $ docker service update busybox --replicas 12 $ docker service update whoami --replicas 12 Create extra instances (replicas) … on the cluster

Slide 24

Slide 24 text

Raspberry Pi Cluster with Docker Swarm blacknode greennode rednode pinknode yellownode whitenode Service A Service B Service C Docker Swarm runs multiple instances of the services, which node is no longer relevant.

Slide 25

Slide 25 text

Raspberry Pi Cluster with Docker Swarm Visualization of the Docker Swarm running on the blacknode [source: alexellis2/visualizer-arm]

Slide 26

Slide 26 text

Docker Swarm deployment with Ansible

Slide 27

Slide 27 text

Docker Swarm deployment with Ansible Ansible is used to deploy the Docker Swarm on the Raspberry Pi stack. inventory playbooks + =

Slide 28

Slide 28 text

Docker Swarm deployment: Ansible playbooks PLAYBOOK blacknode greennode rednode pinknode yellownode whitenode

Slide 29

Slide 29 text

Docker Swarm deployment: Ansible playbooks PLAYBOOK blacknode greennode rednode pinknode yellownode whitenode swarmSetup.yml: - Initialize the swarm - Open the visualization page - Add the nodes to the cluster - Start the visualization container

Slide 30

Slide 30 text

Docker Swarm deployment: Ansible playbooks PLAYBOOK blacknode greennode rednode pinknode yellownode whitenode swarmSetup.yml: - Initialize the swarm - Open the visualization page - Add the nodes to the cluster - Start the visualization container

Slide 31

Slide 31 text

Docker Swarm deployment: Ansible playbooks PLAYBOOK blacknode greennode rednode pinknode yellownode whitenode swarmSetup.yml: - Initialize the swarm - Open the visualization page - Add the nodes to the cluster - Start the visualization container

Slide 32

Slide 32 text

Docker Swarm deployment: Ansible playbooks PLAYBOOK blacknode greennode rednode pinknode yellownode whitenode swarmSetup.yml: - Initialize the swarm - Open the visualization page - Add the nodes to the cluster - Start the visualization container

Slide 33

Slide 33 text

Docker Swarm deployment: Ansible playbooks PLAYBOOK blacknode greennode rednode pinknode yellownode whitenode servicesSetup.yml: - Start the whoami service - Start the busybox service - Open the busybox page - Open the whoami page

Slide 34

Slide 34 text

Docker Swarm deployment: Ansible playbooks PLAYBOOK blacknode greennode rednode pinknode yellownode whitenode servicesSetup.yml: - Start the whoami service - Start the busybox service - Open the busybox page - Open the whoami page

Slide 35

Slide 35 text

Docker Swarm deployment: Ansible playbooks PLAYBOOK blacknode greennode rednode pinknode yellownode whitenode servicesSetup.yml: - Start the whoami service - Start the busybox service - Open the busybox page - Open the whoami page

Slide 36

Slide 36 text

Docker Swarm deployment: Ansible playbooks PLAYBOOK blacknode greennode rednode pinknode yellownode whitenode servicesSetup.yml: - Start the whoami service - Start the busybox service - Open the busybox page - Open the whoami page

Slide 37

Slide 37 text

Docker Swarm demo: Add replicas blacknode greennode rednode pinknode yellownode whitenode $ docker service update whoami --replicas 10 $ docker service update busybox --replicas 10

Slide 38

Slide 38 text

Docker Swarm deployment: Ansible playbooks blacknode greennode rednode pinknode yellownode whitenode Check the visualization page

Slide 39

Slide 39 text

Docker Swarm demo: Ansible playbooks PLAYBOOK blacknode greennode rednode pinknode yellownode whitenode whitenodeTeardown.yml: - Remove the white node - Leave the cluster

Slide 40

Slide 40 text

Docker Swarm demo: Ansible playbooks PLAYBOOK blacknode greennode rednode pinknode yellownode whitenode whitenodeTeardown.yml: - Remove the white node - Leave the cluster

Slide 41

Slide 41 text

Docker Swarm deployment: Ansible playbooks blacknode greennode rednode pinknode yellownode whitenode Check the visualization page

Slide 42

Slide 42 text

Docker Swarm deployment: Ansible playbooks PLAYBOOK blacknode greennode rednode pinknode yellownode whitenode whitenodeSetup.yml: - Add the white node - Get the worker token

Slide 43

Slide 43 text

Docker Swarm deployment: Ansible playbooks PLAYBOOK blacknode greennode rednode pinknode yellownode whitenode whitenodeSetup.yml: - Add the white node - Get the worker token

Slide 44

Slide 44 text

Docker Swarm blacknode greennode rednode pinknode yellownode whitenode Check the visualization page

Slide 45

Slide 45 text

Docker Swarm: Add replicas blacknode greennode rednode pinknode yellownode whitenode $ docker service update whoami --replicas 18 $ docker service update busybox --replicas 18

Slide 46

Slide 46 text

Docker Swarm blacknode greennode rednode pinknode yellownode whitenode Check the visualization page

Slide 47

Slide 47 text

Questions ?

Slide 48

Slide 48 text

Additional info

Slide 49

Slide 49 text

Addressing the GPIO pins via bash Bash Script Control of GPIO Ports The Pi's GPIO ports can be controlled from the command line (i.e. bash), python scripts, and C/C++ programs. There are 17 GPIO ports available on the Pi. Some of them have special purposes or special hardware configurations and should be avoided for normal use. Source: http://raspberrypi-aa.github.io/session2/bash.html

Slide 50

Slide 50 text

Bash command Bash commando for showing the different whoami instances: for i in {1..20}; do curl http://192.168.178.32:8082;done

Slide 51

Slide 51 text

Ansible playbooks 1/3 Startup sequence: Initialize the GPIO files: $ ansible-playbook -i inventory gpioSetup.yml Set up the swarm cluster: $ ansible-playbook -i inventory swarmSetup.yml Start the services: $ ansible-playbook -i inventory servicesSetup.yml

Slide 52

Slide 52 text

Ansible playbooks 2/3 Swarm playtime: $ ssh [email protected] $ docker service update whoami --replicas 10 $ docker service update busybox --replicas 10 Remove the white node from the cluster: $ ansible-playbook -i inventory whitenodeTeardown.yml Add the white node to the cluster: $ ansible-playbook -i inventory whitenodeSetup.yml Add extra replicas: $ docker service update whoami --replicas 12 $ docker service update busybox --replicas 12

Slide 53

Slide 53 text

Ansible playbooks 3/3 Teardown sequence: Shutdown the services: $ ansible-playbook -i inventory servicesTeardown.yml Teardown the cluster: $ ansible-playbook -i inventory swarmTeardown.yml Remove the GPIO files (optional): $ ansible-playbook -i inventory gpioTeardown.yml Shutdown the Raspberry Pi stack: $ ansible-playbook -i inventory shutdown.yml

Slide 54

Slide 54 text

Find a headless Raspberry Pi b8:27:eb is the Mac address signature of a Raspberry Pi Use arp On the command line run: $ arp -a | grep b8:27:eb | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' or just $ arp -a | grep b8:27:eb Use fing Download and install fing from the Fing website [https://www.fing.io/download-free- ip-scanner-for-desktop-linux-windows-and-osx/] Fing needs sudo-rights to run. Router Log in to your router and look up the IP-address assigned to the Pi.

Slide 55

Slide 55 text

Useful links: Hypriot Blog: http://blog.hypriot.com/ Swarm mode key concepts: https://docs.docker.com/engine/swarm/key-concepts/ Swarm mode overview: https://docs.docker.com/engine/swarm/ SSH Keys, How-To: https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 Raspberry Pi Dramble wiki: http://www.pidramble.com/wiki Tooling: Flash tool: https://github.com/hypriot/flash Swarm visualization (ARM): https://github.com/manomarks/docker-swarm-visualizer Homebrew: http://brew.sh

Slide 56

Slide 56 text

Raspberry Pi Stack costs: *Prices are rounded up, shipping costs left out. Parts Price (€)* Supplier Switch 9 Amazon (.de) Patch cables 9 Amazon (.de) Anker PowerPort 40 Amazon (.de) Micro-SD cards (x6) 30 Norrod Dragan box 10 Ikea Raspberry Pi (x6) 260 Okaphone Electronics 16 Okaphone PVC “spacer bolts” 25 Okaphone Total € 399 The costs above are without the failed attempts and many nightly hours

Slide 57

Slide 57 text

No content