Upload
eueung-mulyana
View
350
Download
1
Embed Size (px)
Citation preview
Container Cluster
Consul & SwarmEueung Mulyana
http://eueung.github.io/docker-stuff/consulCodeLabs | Attribution-ShareAlike CC BY-SA
1 / 26
Outline
Consul - Introduction
RPI Swarm Cluster + Consul
2 / 26
Consul
Introduction
3 / 26
4 / 26
ConsulConsul is s a tool for discovering and con�guring services in
our infrastructure.
Key FeaturesService Discovery | Health Checking | Key/Value Store |
Multi Datacenter
Service DiscoveryClients of Consul can provide a service, such as api or mysql,
and other clients can use Consul to discover providers of agiven service. Using either DNS or HTTP, applications can
easily �nd the services they depend upon.
Health CheckingConsul clients can provide any number of health checks,either associated with a given service ("is the webserverreturning 200 OK"), or with the local node ("is memory
utilization below 90%"). This information can be used by anoperator to monitor cluster health, and it is used by theservice discovery components to route tra�c away from
unhealthy hosts.
5 / 26
Key/Value StoreApplications can make use of Consul's hierarchical key/valuestore for any number of purposes, including dynamiccon�guration, feature �agging, coordination, leader election,and more. The simple HTTP API makes it easy to use.
Multi DatacenterConsul supports multiple datacenters out of the box. This meansusers of Consul do not have to worry about building additionallayers of abstraction to grow to multiple regions.
Ref: Introduction - Consul by HashiCorp
ArchitectureConsul is a distributed, highly available
system.
Every node that provides services to Consulruns a Consul agent. Running an agent is
not required for discovering other servicesor getting/setting key/value data. The agent
is responsible for health checking theservices on the node as well as the node
itself.
6 / 26
The agents talk to one or more Consul servers. The Consulservers are where data is stored and replicated. The serversthemselves elect a leader. While Consul can function with oneserver, 3 to 5 is recommended to avoid failure scenarios leadingto data loss. A cluster of Consul servers is recommended foreach datacenter.
Components of your infrastructure that need to discover otherservices or nodes can query any of the Consul servers or any ofthe Consul agents. The agents forward queries to the serversautomatically.
Each datacenter runs a cluster of Consul servers. When a cross-datacenter service discovery or con�guration request is made,the local Consul servers forward the request to the remotedatacenter and return the result.
Ref: Introduction - Consul by HashiCorp
7 / 26
RPI Swarm Cluster + Consul
8 / 26
Let's rebuild our previous container clusterwith Consul..
Check it again if necessary: Docker Swarm Cluster
9 / 26
10 / 26
A 3-Node RPIClusternode1192.168.1.102
node2192.168.1.101
node3192.168.1.100
$ ssh-keygen -R node1.local$ ssh-copy-id -oStrictHostKeyChecking=no -oCheckHostIP=no root@$node1.local
# if necessary$ ssh -oStrictHostKeyChecking=no -oCheckHostIP=no root@$node1.local$ ssh-keygen -R 192.168.1.102
11 / 26
A Note
SSH Setting
# etc/default/dockerDOCKER_OPTS="--storage-driver=overlay -D -H tcp://0.0.0.0:2375 --cluster-store consul://192.168.1.102:8500 --cluster-advertise=eth0:2375"
# if necessary$ systemctl restart docker$ docker info $ ps aux | grep docker
12 / 26
Engine Config
DOCKER_OPTS
$ ./start.sh node1.local
# start.sh
function getip() { (traceroute $1 2>&1 | head -n 1 | cut -d\( -f 2 | cut
IP_ADDRESS=$(getip $1)echo $IP_ADDRESS
docker -H $IP_ADDRESS:2375 run \ -d --net=host --name=consul \ -v /data -p 8500:8500 \ hypriot/rpi-consul:0.6.4 agent -server -data-dir /data -bootstrap-expect -ui-dir=/ui \ -advertise=$IP_ADDRESS -bind=$IP_ADDRESS -client=$IP_ADDRESS
docker -H $IP_ADDRESS:2375 run \ -d -p 10000:6000 --name=swarm-master \ hypriot/rpi-swarm:1.2.1 manage -H 0.0.0.0:6000 \ --discovery-opt="kv.path=docker/nodes" \ consul://$IP_ADDRESS:8500
13 / 26
Start Consul &Swarm Master
$ export DOCKER_HOST=tcp://192.168.1.102:10000$ docker run -d -p 8080:80 hypriot/rpi-nano-httpd571d31928b3db90fc6baffa088c25c645f8d55d5e144dc03816ef5f6af62ae21
$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES571d31928b3d hypriot/rpi-nano-httpd "/httpd 80" 8d897b5aeab29 hypriot/rpi-swarm:1.2.1 "/swarm manage -H 0.0" dc1bb0bd5188 hypriot/rpi-consul:0.6.4 "/consul agent -serve"
14 / 26
Check & Test
$ docker info
Containers: 3 Running: 3 - Paused: 0 - Stopped: 0Images: 11Server Version: swarm/1.2.1Role: primaryStrategy: spreadFilters: health, port, containerslots, dependency, affinity, constraintNodes: 3 node1: 192.168.1.102:2375 - ID: ASSH:N743:XQ4D:2B3A:LQA6:ESIO:PHBI:RPN7:NWMP:5WK2:4X4F:WNY5 - Status: Healthy - Containers: 2 - Reserved CPUs: 0 / 4 - Reserved Memory: 0 B / 971.8 MiB - Labels: executiondriver=native-0.2, kernelversion=4.1.17-hypriotos-v7+, operatingsystem=Raspbian GNU/Linux - Error: (none) - UpdatedAt: 2016-05-15T08:34:02Z - ServerVersion: 1.10.2 node2: 192.168.1.101:2375 - Containers: 1 - Reserved CPUs: 0 / 4 - Reserved Memory: 0 B / 971.8 MiB node3: 192.168.1.100:2375 - Containers: 0 - Reserved CPUs: 0 / 4 - Reserved Memory: 0 B / 971.8 MiB...Kernel Version: 4.1.17-hypriotos-v7+ - Operating System: linux - Architecture: armCPUs: 12Total Memory: 2.847 GiBName: d897b5aeab29
15 / 26
Check & Test
Consul UI
16 / 26
Consul UI
17 / 26
Consul UI
18 / 26
$ docker run -d -p 9000:9000 hypriot/rpi-dockerui:v0.9.0 -e http://192.168a08588d3e7888952875e9f14496ccf5e943af954a8e70a4c51439025ff31a943
$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESa08588d3e788 hypriot/rpi-dockerui "/dockerui -e http://" 6571d31928b3d hypriot/rpi-nano-httpd "/httpd 80" About an hour ago Up About an hour d897b5aeab29 hypriot/rpi-swarm:1.2.1 "/swarm manage -H 0.0" About an hour ago Up About an hour dc1bb0bd5188 hypriot/rpi-consul:0.6.4 "/consul agent -serve" About an hour ago Up About an hour node1/consul
19 / 26
Now: UI for Docker
Try DockerUI
DockerUI
20 / 26
DockerUI
21 / 26
DockerUI
22 / 26
DockerUI
23 / 26
Refs
24 / 26
Refs1. Introduction - Consul by HashiCorp2. Consul Architecture - Consul by HashiCorp3. kevana/ui-for-docker: An uno�cial web interface for Docker, formerly known
as DockerUI4. consul @ docker hub5. progrium/consul @ docker hub6. gliderlabs/consul @ docker hub | consul-agent | consul-server
25 / 26
ENDEueung Mulyana
http://eueung.github.io/docker-stuff/consulCodeLabs | Attribution-ShareAlike CC BY-SA
26 / 26