Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Docker Service Discovery & Composition

Docker Service Discovery & Composition

Day of Docker 2015 Oslo Conference

Avatar for Jonathan Camp

Jonathan Camp

December 01, 2015

More Decks by Jonathan Camp

Other Decks in Technology

Transcript

  1. Service Discovery & Composition DoD - Oslo - 2015 Jonathan

    Camp git clone https://github.com/kung-foo/dod-workshop cd dod-workshop && ./workshop-init.sh
  2. About Me • 5 years at Blue Coat Norway AS

    (formerly Norman) • 10 years at Lawrence Livermore National Laboratory (U.S. Department of Energy) • Jeg snakker litt norsk, men du ikke vil at jeg skal! • Architect for Blue Coat’s Malware Analysis Appliance git clone https://github.com/kung-foo/dod-workshop cd dod-workshop && ./workshop-init.sh http://keybase.io/kung_foo 8F1F B151 D565 3923 @irondojo
  3. Goals 1. Why do we need service discovery? 2. Is

    discovery sufficient? 3. DIY or “batteries included”?
  4. Workshop Format and Requirements • Code > PowerPoint • Interactive:

    Show. Discuss. Share. • Four hands-on demos Who wants to be my OS X guru? • Docker ◦ 1.9+ if you want to try the newest network stuff • docker-compose
  5. nginx.conf upstream backend { server node-1:8080; server node-2:8080; server ???:8080;

    # weave address? } server { listen 80 default_server; }
  6. Questions • What happens when a service container dies? •

    Can we dynamically add and remove node.js containers? • How do we avoid hard-coding location/ports? • Why are all Docker examples based on nginx + node.js?
  7. Bootstrapping the Workshop git clone https://github.com/kung-foo/dod-workshop cd dod-workshop && ./workshop-init.sh

    Notes: 1. If you are using boot2docker, please allocate more than one CPU 2. Did you miss a step? Take a look at dod-workshop/demo-*/SCRIPT.md
  8. Workshop Roadmap Demo #1 Python app + redis Demo #2

    += consul += service registry Demo #3 += service health Demo #4 -= Python += golang += consul template += redis slaves += scaling += benchmarks
  9. Demo 01 1. Goals a. Make sure everyone’s env is

    ready to go b. Use docker-compose c. Understand: docker run --link d. Scale redis container by one e. Scale web container by one 2. Caveat for 1.9 Show me the code!
  10. Demo 02 1. Goals a. find a better source of

    current containers and services 2. New a. gliderlabs/registrator b. consul (will introduce fully in next demo) 3. Notes a. we could just use the docker API, why not? The Registrator
  11. gliderlabs/registrator • A service registry populated from the Docker API

    • Data is stored various backends: Consul, etcd, SkyDNS 2 • Requires a Docker daemon volume mount • Sponsored by DigitalOcean and Weaveworks
  12. Consul Key/Value Store • We’ll cover more Consul details in

    demo-03 • Distributed RESTful KV store
  13. Where are we so far? Links? Very limited, static, and

    messy. /etc/hosts? Limited, getting better with Docker 1.9 Docker API? Requires access to the Docker daemon. Registrator? Simple, fast, combined with Consul can provide health checks. Can we do better?
  14. Demo 03 1. Goals a. service health checks if you

    are going to discover services, you should also do health checks 2. New a. consul i. service defs ii. health checks b. consul-ui
  15. Consul Part 2 • Agent based distributed cluster management ◦

    DNS ◦ Service Definitions ◦ Health Checks ◦ Key/Value Store • Based on Serf ◦ Based on MemberList ▪ Gossip protocol implemented using SWIM
  16. Consul Service { "service": { "name": "redis", "tags": ["slave"], "port":

    6379, "checks": [{ "script": "redis-check", // * "interval": "5s" }] } } /demo-04-full/slave/root/etc/consul.d/redis.json see: redis-check
  17. Demo 04 1. Goals: a. fully working scalable cluster with

    health checking b. customize a health check 2. New: a. consul-template b. rrproxy c. Apache Bench
  18. Consul Template Master = "redis-master" # note link Slaves =

    [ {{ range service "redis" }} {{ if .Tags | contains "slave" }} "{{ .Address }}", {{ end }} {{ end }} ] /* /^(o.o)^\ /^(o.o)^\ /^(o.o)^\ */ Master = "redis-master" Slaves = [ "192.168.200.4", "192.168.200.7", "192.168.200.8", ] • Rewrites config files based on changes in Consul’s registry • Based on golang syntax • TIL: parseJSON
  19. rrproxy • Simple reverse proxy • GET /db/{key-name} returns value

    from random redis-slave • POST /db/{key-name} sets value in redis-master • configuration read from a TOML file
  20. Used But Not Covered • Alpine Linux ◦ http://www.alpinelinux.org/ •

    s6-overlay ◦ https://github.com/just-containers/s6-overlay
  21. Wrap Up • Nothing worked? • Next steps: ◦ Cluster

    scheduling (i.e. Kubernetes, Nomad, AWS ECS) ◦ Networking (i.e. Weave, ZeroTier)