0% found this document useful (0 votes)
158 views43 pages

Docker Cluster: With Swarm, Consul, Registrator and Consul-Template

The document discusses using Docker swarm, Consul, Registrator and Consul Template together to create a Docker cluster with service discovery and auto-configuration capabilities. It describes how to create a swarm cluster with Consul for service discovery, use Registrator to automatically register Docker services with Consul, and Consul Template to generate configuration files from Consul services to enable load balancing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views43 pages

Docker Cluster: With Swarm, Consul, Registrator and Consul-Template

The document discusses using Docker swarm, Consul, Registrator and Consul Template together to create a Docker cluster with service discovery and auto-configuration capabilities. It describes how to create a swarm cluster with Consul for service discovery, use Registrator to automatically register Docker services with Consul, and Consul Template to generate configuration files from Consul services to enable load balancing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Docker cluster

With swarm, consul, registrator and consultemplate

jmaitrehenry

Overview
Create a swarm cluster
Manage a swarm cluster
Service discovery
Service auto-configuration
2015-06-15

1 linux server

An host running Linux

2015-06-15

With docker

Docker daemon
An host running Linux

2015-06-15

2 linux servers with docker

Docker daemon

Docker daemon

An host running Linux

An host running Linux

2015-06-15

How can I manage them?

Individually? Why not if you like that


On a cluster with a manager? Yeah!

2015-06-15

Docker swarm

Docker Swarm is native clustering for Docker. It turns a pool of Docker hosts into a single, virtual host
https://github.com/docker/swarm

2015-06-15

How do I add a node to swarm ?

Swarm need to register node IP and docker tcp port

somewhere
Consul have a Key/Value store and swarm can register node
on it

2015-06-15

What is Consul?

Consul is a distributed, highly available system and provides:


Service discovery
Failure detection
Key/Value store
Bonus: supports multiple datacenter
2015-06-15

Create a swarm cluster


Consul
daemon

Consul host

Docker daemon

Docker daemon

An host running Linux

An host running Linux

Swarm cluster

2015-06-15

10

How do I register an node to consul ?

With swarm !
dockerrundswarm:0.3.0rc2join
addr=10.1.1.231:2375consul://10.1.8.32:8500/dc1

2015-06-15

11

How do I register an node to consul ?


swarm:0.3.0-rc2 ? Support docker login
--addr=<public host IP>:<port of docker http API>
consul://<IP of consul server>:<port>/<datacenter>
dockerrundswarm:0.3.0rc2join
addr=10.1.1.231:2375consul://10.1.8.32:8500/dc1
2015-06-15

12

Create a swarm cluster


Consul
daemon

Register node to consul K/V store

Consul host

Docker daemon

Docker daemon

An host running Linux

An host running Linux

Swarm cluster

2015-06-15

13

How can I manage my swarm cluster?

With swarm !
dockerrundp2375:2375swarmmanage
consul://10.1.8.32:8500/dc1

2015-06-15

14

How can I manage my swarm cluster?

#exportDOCKER_HOST=tcp://<managerIP>:<port>
#docker<dockercmd>
Without TLS enabled (dev only please ) :
# unsetDOCKER_TLS_VERIFY

2015-06-15

15

How can I manage my swarm cluster?

2015-06-15

16

Manage a swarm cluster


manager
Consul
daemon

Register node
Docker
daemo
n
My laptop

Consul host
Docker
daemo
n
An host
Swarm
cluster

Docker
daemo
n
An host
2015-06-15

17

Manage a swarm cluster


Get node list
Consul
daemon

manager

Register node
Docker
daemo
n
My laptop

Consul host
Docker
daemo
n
An host
Swarm
cluster

Docker
daemo
n
An host
2015-06-15

18

Manage a swarm cluster


Get node list
Consul
daemon

manager

Register node
Docker
daemo
n
My laptop

Consul host
Docker
daemo
n
An host
Swarm
cluster

Docker
daemo
n

Manage hosts

An host
2015-06-15

19

Ok, fine, I have 3 docker containers


but how they know each other?

First, we need to register service somewhere


Second, each service can ask somewhere where are other
service

2015-06-15

20

Service discovery

Service discoveryis a key component of most distributed


systems and serviceoriented architectures. The problem seems
simple at first: How do clients determine the IP and port
for aservicethat exist on multiple hosts?

2015-06-15

21

Oh, consul is a service discovery!


Yes it is!
Service list: http://10.1.8.32:8500/v1/catalog/services

2015-06-15

22

Consul
Service details:

http://10.1.8.32:8500/v1/catalog/service/statsd-8125
Consul server

2015-06-15

23

Consul
Service details:

http://10.1.8.32:8500/v1/catalog/service/statsd-8125
Consul server
Docker node

2015-06-15

24

Consul
Service details:

http://10.1.8.32:8500/v1/catalog/service/statsd-8125
Consul server
Docker node
Service address

2015-06-15

25

How can docker register services in


consul?

With a service registry bridge for Docker like Registrator

2015-06-15

26

Registrator
Service registry bridge for Docker
Registrator automatically register/deregisters services for

Docker containers based on published ports and metadata


from the container environment.
https://github.com/gliderlabs/registrator

2015-06-15

27

Registrator

On each swarm node

2015-06-15

28

Registrator

On each swarm node

Local docker socket


2015-06-15

29

Registrator

On each swarm node

Local docker socket

Public node IP
2015-06-15

30

Demo

2015-06-15

31

2015-06-15

32

2015-06-15

33

Ok, I have some nginx running, how


can I have a single entry point?

With a load balancer (haproxy) with an auto update


configuration

2015-06-15

34

Consul template
The daemonconsul-templatequeries aConsulinstance and
updates any number of specified templates on the filesystem.
As an added bonus,consul-templatecan optionally run
arbitrary commands when the update process completes
https://github.com/hashicorp/consul-template
2015-06-15

35

Consul template - command

2015-06-15

36

Consul template where to run it?

Where you want, the only condition is to have access to

consul server.
You could have it in a container
You could have it somewhere else

2015-06-15

37

Consul template template file

Service name

2015-06-15

38

Consul template template file

Service name
Service IP

2015-06-15

39

Consul template template file

Service name
Service IP
Service port

2015-06-15

40

Consul template - testing

2015-06-15

41

Consul template - testing


Dump generated template and exit

2015-06-15

42

Thanks!

2015-06-15

43

You might also like