docker service registration and discovery

53
Service Registration and Discovery with Michael Richardson @m_richo

Upload: mrichardson

Post on 15-Jul-2015

1.210 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: Docker Service Registration and Discovery

Service Registration

and Discovery with

Michael Richardson @m_richo

Page 2: Docker Service Registration and Discovery

$whoami

• Michael Richardson

• Engineer @ odecee

• @m_richo

• http://www.mricho.com

• I like DevOps*

• Docker has grown on me in the last 6 months

* My definition of DevOps is likely different from yours

Page 3: Docker Service Registration and Discovery

Agenda

• What is Service Registration & Discovery?

• Consul

– tool to store information about services

• Registrator

– tool to register Docker services

• Consul-template

– tool to query registered services and apply configuration.

• Demo

Page 4: Docker Service Registration and Discovery

Service Registration and Discovery

What is it?

Page 5: Docker Service Registration and Discovery

Service Registration and Discovery

What is it?

“Service Discovery Protocols (SDP) are

network protocols which allow automatic

detection of devices and services offered by

these devices on a computer network.”

Source: http://en.wikipedia.org/wiki/Service_discovery

Page 6: Docker Service Registration and Discovery

Service Registration and Discovery

What is it?

Basically… how do clients determine the

network details of desired services.

Page 7: Docker Service Registration and Discovery

Service Registration and Discovery

Existing techniques?

• DNS (perhaps Dynamic DNS)

• Puppet exported resources

• Chef Search

• many others

Page 8: Docker Service Registration and Discovery

Service Registration and Discovery

These approaches can struggle in a docker world

Image source: http://www.ideachampions.com/weblogs/archives/2011/09/the_top_100_lam.shtml

Page 9: Docker Service Registration and Discovery

Service Registration and Discovery

These approaches can struggle in a docker world

• DNS

Page 10: Docker Service Registration and Discovery

Service Registration and Discovery

These approaches can struggle in a docker world

• DNS

– TTL and caching can often be an issue

Page 11: Docker Service Registration and Discovery

Service Registration and Discovery

These approaches can struggle in a docker world

• DNS

– TTL and caching can often be an issue

– Just try doing interesting DNS things in an enterprise.

Page 12: Docker Service Registration and Discovery

Service Registration and Discovery

These approaches can struggle in a docker world

• DNS

– TTL and caching can often be an issue

– Just try doing interesting DNS things in an enterprise.

– Containers don’t have a unique IP address. Simple IP

based DNS isn’t sufficient. *

* SRV records can be an option

Page 13: Docker Service Registration and Discovery

Service Registration and Discovery

These approaches can struggle in a docker world

• DNS– TTL and caching can often be an issue

– Just try doing interesting DNS things in an enterprise.

– Containers don’t have a unique IP address. Simple IP based DNS isn’t sufficient. *

• Config Management agents

* SRV records can be an option

Page 14: Docker Service Registration and Discovery

Service Registration and Discovery

These approaches can struggle in a docker world

• DNS– TTL and caching can often be an issue

– Just try doing interesting DNS things in an enterprise.

– Containers don’t have a unique IP address. Simple IP based DNS isn’t sufficient. *

• Config Management agents– I’m resistant to running agents within a container.

– CM agent run intervals are probably not frequent enough.

* SRV records can be an option

Page 15: Docker Service Registration and Discovery

Service Registration and Discovery

Are there any new tools for Services Discovery?

Page 16: Docker Service Registration and Discovery

Service Registration and Discovery

• Zookeeper

• Doozer

• Etcd

• SmartStack

• Eureka

• SkyDNS

• consul

Yep. Quite a few…

Page 17: Docker Service Registration and Discovery

Service Registration and Discovery

• Zookeeper

• Doozer

• Etcd

• SmartStack

• Eureka

• SkyDNS

• consul

Yep. Quite a few…

Page 18: Docker Service Registration and Discovery

Consul

“Service Discovery and

configuration made easy.

Distributed, highly available

and datacenter aware.”

Page 19: Docker Service Registration and Discovery

Consul

Key features…

• Service Discovery

• Health Checking

• Key/Value Storage

• Multi Datacenter

Page 20: Docker Service Registration and Discovery

Consul

Key features…

• Service Discovery

• Health Checking

• Key/Value Storage

• Multi Datacenter

Page 21: Docker Service Registration and Discovery

Consul - example

Page 22: Docker Service Registration and Discovery

Consul - example

Consul service definition for nginx web server

Page 23: Docker Service Registration and Discovery

Consul + Docker

How should I use consul with docker?

Page 24: Docker Service Registration and Discovery

Consul + Docker

How should I use consul with docker?

Option 1: run 1 Consul client agent in every

container to register its service

Or

Option 2: run 1 consul client agent per Docker

host that is responsible for all the containers on it

Page 25: Docker Service Registration and Discovery

Consul + Docker

How should I use consul with docker?

Option 1: run 1 Consul client agent in every

container to register its service

Or

Option 2: run 1 consul client agent per Docker

host that is responsible for all the containers on it

Option 2 makes more sense to me

Page 26: Docker Service Registration and Discovery

Consul + Docker

Docker host running some containers

Page 27: Docker Service Registration and Discovery

Consul + Docker

Add a Consul Agent as a container

Page 28: Docker Service Registration and Discovery

Consul + Docker

Which talks to the consul cluster

Page 29: Docker Service Registration and Discovery

Consul + Docker

Next Question?

How do we register the

container services with the

consul agent?

Page 30: Docker Service Registration and Discovery

Consul + Docker

Question?

How do we register the

container services with the

consul agent?

Use

Registrator!

Page 31: Docker Service Registration and Discovery

Registrator

• https://github.com/gliderlabs/registrator

• Automatically registers/deregisters services for docker

containers

• Supported Registry services include consul, etcd and SkyDNS

2

• Reads events from Docker Socket (/var/run/docker.sock)

• Run on each Docker host*

* Ideally run it as a container

Page 32: Docker Service Registration and Discovery

Registrator

Installation instructions

Page 33: Docker Service Registration and Discovery

Registrator

Installation instructions

Page 34: Docker Service Registration and Discovery

Registrator

Starting Registrator

Page 35: Docker Service Registration and Discovery

Registrator

Starting Registrator

Page 36: Docker Service Registration and Discovery

Registrator

Starting Registrator

pass docker socket to container

Specify service registry endpoint (eg consul)

Page 37: Docker Service Registration and Discovery

How does it work

Page 38: Docker Service Registration and Discovery

How does it work

• Start containers for consul

and registrator

Page 39: Docker Service Registration and Discovery

How does it work

• Start containers for consul

and registrator

• Registrator watches for

container start and die

events

Page 40: Docker Service Registration and Discovery

How does it work

• Start containers for consul

and registrator

• Registrator watches for

container start and die

events

• Start new container

Page 41: Docker Service Registration and Discovery

How does it work

• Start containers for consul

and registrator

• Registrator watches for

container start and die

events

• Start new container

• Registrator informs consul

of service A’s metadata

(IP/port/name/tag)

Page 42: Docker Service Registration and Discovery

Service information is now in

Consul. How can we access it?

Page 43: Docker Service Registration and Discovery

• Consul’s HTTP API

• Consul’s DNS API

• Consul-template (via HTTP

API)

Consul Access

Page 44: Docker Service Registration and Discovery

• Consul’s HTTP API

• Consul’s DNS API

• Consul-template (via HTTP

API)

Consul Access

Page 45: Docker Service Registration and Discovery

Consul-template

What does it do?

Page 46: Docker Service Registration and Discovery

Consul-template

What does it do?

• Populate template files with data from

Consul.

• Optionally run commands when consul

data changes.

Page 47: Docker Service Registration and Discovery

Consul-template – example 1

Page 48: Docker Service Registration and Discovery

Consul-template – example 1

Page 49: Docker Service Registration and Discovery

Consul-template – example 2

Page 50: Docker Service Registration and Discovery

Consul-template – example 2

Page 51: Docker Service Registration and Discovery

Time for a Demo

Page 52: Docker Service Registration and Discovery

links

• https://consul.io/

• https://github.com/hashicorp/consul-template

• https://github.com/gliderlabs/registrator

• https://github.com/CiscoCloud/microservices-

infrastructure

• http://jasonwilder.com/blog/2014/02/04/service-

discovery-in-the-cloud/

Page 53: Docker Service Registration and Discovery

Questions?

Thanks for listening

@m_richo