Slide 1

Slide 1 text

Container Cluster Consul & Swarm Eueung Mulyana http://eueung.github.io/docker-stuff/consul CodeLabs | Attribution-ShareAlike CC BY-SA 1 / 26

Slide 2

Slide 2 text

Outline Consul - Introduction RPI Swarm Cluster + Consul 2 / 26

Slide 3

Slide 3 text

Consul Introduction 3 / 26

Slide 4

Slide 4 text

4 / 26 Consul Consul is s a tool for discovering and con guring services in our infrastructure. Key Features Service Discovery | Health Checking | Key/Value Store | Multi Datacenter

Slide 5

Slide 5 text

Service Discovery Clients of Consul can provide a service, such as api or mysql, and other clients can use Consul to discover providers of a given service. Using either DNS or HTTP, applications can easily nd the services they depend upon. Health Checking Consul clients can provide any number of health checks, either associated with a given service ("is the webserver returning 200 OK"), or with the local node ("is memory utilization below 90%"). This information can be used by an operator to monitor cluster health, and it is used by the service discovery components to route tra c away from unhealthy hosts. 5 / 26 Key/Value Store Applications can make use of Consul's hierarchical key/value store for any number of purposes, including dynamic con guration, feature agging, coordination, leader election, and more. The simple HTTP API makes it easy to use. Multi Datacenter Consul supports multiple datacenters out of the box. This means users of Consul do not have to worry about building additional layers of abstraction to grow to multiple regions. Ref: Introduction - Consul by HashiCorp

Slide 6

Slide 6 text

Architecture Consul is a distributed, highly available system. Every node that provides services to Consul runs a Consul agent. Running an agent is not required for discovering other services or getting/setting key/value data. The agent is responsible for health checking the services on the node as well as the node itself. 6 / 26 The agents talk to one or more Consul servers. The Consul servers are where data is stored and replicated. The servers themselves elect a leader. While Consul can function with one server, 3 to 5 is recommended to avoid failure scenarios leading to data loss. A cluster of Consul servers is recommended for each datacenter. Components of your infrastructure that need to discover other services or nodes can query any of the Consul servers or any of the Consul agents. The agents forward queries to the servers automatically. 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 remote datacenter and return the result. Ref: Introduction - Consul by HashiCorp

Slide 7

Slide 7 text

7 / 26

Slide 8

Slide 8 text

RPI Swarm Cluster + Consul 8 / 26

Slide 9

Slide 9 text

Let's rebuild our previous container cluster with Consul.. Check it again if necessary: Docker Swarm Cluster 9 / 26

Slide 10

Slide 10 text

10 / 26 A 3-Node RPI Cluster node1 192.168.1.102 node2 192.168.1.101 node3 192.168.1.100

Slide 11

Slide 11 text

$ s s h - k e y g e n - R n o d e 1 . l o c a l $ s s h - c o p y - i d - o S t r i c t H o s t K e y C h e c k i n g = n o - o C h e c k H o s t I P = n o r o o t @ $ n o d e 1 . l o c a l # i f n e c e s s a r y $ s s h - o S t r i c t H o s t K e y C h e c k i n g = n o - o C h e c k H o s t I P = n o r o o t @ $ n o d e 1 . l o c a l $ s s h - k e y g e n - R 1 9 2 . 1 6 8 . 1 . 1 0 2 11 / 26 A Note SSH Setting

Slide 12

Slide 12 text

# e t c / d e f a u l t / d o c k e r D O C K E R _ O P T S = " - - s t o r a g e - d r i v e r = o v e r l a y - D - H t c p : / / 0 . 0 . 0 . 0 : 2 3 7 5 - - c l u s t e r - s t # i f n e c e s s a r y $ s y s t e m c t l r e s t a r t d o c k e r $ d o c k e r i n f o $ p s a u x | g r e p d o c k e r 12 / 26 Engine Config DOCKER_OPTS

Slide 13

Slide 13 text

$ . / s t a r t . s h n o d e 1 . l o c a l # s t a r t . s h f u n c t i o n g e t i p ( ) { ( t r a c e r o u t e $ 1 2 > & 1 | h e a d - n 1 | c u t - d \ ( - f 2 | c u t I P _ A D D R E S S = $ ( g e t i p $ 1 ) e c h o $ I P _ A D D R E S S d o c k e r - H $ I P _ A D D R E S S : 2 3 7 5 r u n \ - d - - n e t = h o s t - - n a m e = c o n s u l \ - v / d a t a - p 8 5 0 0 : 8 5 0 0 \ h y p r i o t / r p i - c o n s u l : 0 . 6 . 4 a g e n t - s e r v e r - d a t a - d i r / d a t a - b o o t s t r a p - e x p e c t - u i - d i r = / u i \ - a d v e r t i s e = $ I P _ A D D R E S S - b i n d = $ I P _ A D D R E S S - c l i e n t = $ I P _ A D D R E S S d o c k e r - H $ I P _ A D D R E S S : 2 3 7 5 r u n \ - d - p 1 0 0 0 0 : 6 0 0 0 - - n a m e = s w a r m - m a s t e r \ h y p r i o t / r p i - s w a r m : 1 . 2 . 1 m a n a g e - H 0 . 0 . 0 . 0 : 6 0 0 0 \ - - d i s c o v e r y - o p t = " k v . p a t h = d o c k e r / n o d e s " \ c o n s u l : / / $ I P _ A D D R E S S : 8 5 0 0 13 / 26 Start Consul & Swarm Master

Slide 14

Slide 14 text

$ e x p o r t D O C K E R _ H O S T = t c p : / / 1 9 2 . 1 6 8 . 1 . 1 0 2 : 1 0 0 0 0 $ d o c k e r r u n - d - p 8 0 8 0 : 8 0 h y p r i o t / r p i - n a n o - h t t p d 5 7 1 d 3 1 9 2 8 b 3 d b 9 0 f c 6 b a f f a 0 8 8 c 2 5 c 6 4 5 f 8 d 5 5 d 5 e 1 4 4 d c 0 3 8 1 6 e f 5 f 6 a f 6 2 a e 2 1 $ d o c k e r p s C O N T A I N E R I D I M A G E C O M M A N D C R E 5 7 1 d 3 1 9 2 8 b 3 d h y p r i o t / r p i - n a n o - h t t p d " / h t t p d 8 0 " 8 d 8 9 7 b 5 a e a b 2 9 h y p r i o t / r p i - s w a r m : 1 . 2 . 1 " / s w a r m m a n a g e - H 0 . 0 " d c 1 b b 0 b d 5 1 8 8 h y p r i o t / r p i - c o n s u l : 0 . 6 . 4 " / c o n s u l a g e n t - s e r v e " 14 / 26 Check & Test

Slide 15

Slide 15 text

$ d o c k e r i n f o C o n t a i n e r s : 3 R u n n i n g : 3 - P a u s e d : 0 - S t o p p e d : 0 I m a g e s : 1 1 S e r v e r V e r s i o n : s w a r m / 1 . 2 . 1 R o l e : p r i m a r y S t r a t e g y : s p r e a d F i l t e r s : h e a l t h , p o r t , c o n t a i n e r s l o t s , d e p e n d e n c y , a f f i n i t y , c o n s t r a i n t N o d e s : 3 n o d e 1 : 1 9 2 . 1 6 8 . 1 . 1 0 2 : 2 3 7 5 - I D : A S S H : N 7 4 3 : X Q 4 D : 2 B 3 A : L Q A 6 : E S I O : P H B I : R P N 7 : N W M P : 5 W K 2 : 4 X 4 F : W N Y 5 - S t a t u - C o n t a i n e r s : 2 - R e s e r v e d C P U s : 0 / 4 - R e s e r v e d M e m o r y : 0 B / 9 7 1 . 8 M i B - L a b e l s : e x e c u t i o n d r i v e r = n a t i v e - 0 . 2 , k e r n e l v e r s i o n = 4 . 1 . 1 7 - h y p r i o t o s - v 7 + , - E r r o r : ( n o n e ) - U p d a t e d A t : 2 0 1 6 - 0 5 - 1 5 T 0 8 : 3 4 : 0 2 Z - S e r v e r V e r s i o n : 1 . 1 0 . 2 n o d e 2 : 1 9 2 . 1 6 8 . 1 . 1 0 1 : 2 3 7 5 - C o n t a i n e r s : 1 - R e s e r v e d C P U s : 0 / 4 - R e s e r v e d M e m o r y : 0 B / 9 7 1 . 8 M i B n o d e 3 : 1 9 2 . 1 6 8 . 1 . 1 0 0 : 2 3 7 5 - C o n t a i n e r s : 0 - R e s e r v e d C P U s : 0 / 4 - R e s e r v e d M e m o r y : 0 B / 9 7 1 . 8 M i B . . . K e r n e l V e r s i o n : 4 . 1 . 1 7 - h y p r i o t o s - v 7 + - O p e r a t i n g S y s t e m : l i n u x - A r c h i t e c t u C P U s : 1 2 T o t a l M e m o r y : 2 . 8 4 7 G i B N a m e : d 8 9 7 b 5 a e a b 2 9 15 / 26 Check & Test

Slide 16

Slide 16 text

Consul UI 16 / 26

Slide 17

Slide 17 text

Consul UI 17 / 26

Slide 18

Slide 18 text

Consul UI 18 / 26

Slide 19

Slide 19 text

$ d o c k e r r u n - d - p 9 0 0 0 : 9 0 0 0 h y p r i o t / r p i - d o c k e r u i : v 0 . 9 . 0 - e h t t p : / / 1 9 2 . 1 6 8 a 0 8 5 8 8 d 3 e 7 8 8 8 9 5 2 8 7 5 e 9 f 1 4 4 9 6 c c f 5 e 9 4 3 a f 9 5 4 a 8 e 7 0 a 4 c 5 1 4 3 9 0 2 5 f f 3 1 a 9 4 3 $ d o c k e r p s C O N T A I N E R I D I M A G E C O M M A N D C R E a 0 8 5 8 8 d 3 e 7 8 8 h y p r i o t / r p i - d o c k e r u i " / d o c k e r u i - e h t t p : / / " 6 5 7 1 d 3 1 9 2 8 b 3 d h y p r i o t / r p i - n a n o - h t t p d " / h t t p d 8 0 " A b o d 8 9 7 b 5 a e a b 2 9 h y p r i o t / r p i - s w a r m : 1 . 2 . 1 " / s w a r m m a n a g e - H 0 . 0 " A b o d c 1 b b 0 b d 5 1 8 8 h y p r i o t / r p i - c o n s u l : 0 . 6 . 4 " / c o n s u l a g e n t - s e r v e " A b o 19 / 26 Now: UI for Docker Try DockerUI

Slide 20

Slide 20 text

DockerUI 20 / 26

Slide 21

Slide 21 text

DockerUI 21 / 26

Slide 22

Slide 22 text

DockerUI 22 / 26

Slide 23

Slide 23 text

DockerUI 23 / 26

Slide 24

Slide 24 text

Refs 24 / 26

Slide 25

Slide 25 text

Refs 1. Introduction - Consul by HashiCorp 2. Consul Architecture - Consul by HashiCorp 3. kevana/ui-for-docker: An uno cial web interface for Docker, formerly known as DockerUI 4. consul @ docker hub 5. progrium/consul @ docker hub 6. gliderlabs/consul @ docker hub | consul-agent | consul-server 25 / 26

Slide 26

Slide 26 text

END Eueung Mulyana http://eueung.github.io/docker-stuff/consul CodeLabs | Attribution-ShareAlike CC BY-SA 26 / 26