Orchestra)ng Containers with Consul and Terraform Mitchell - - PowerPoint PPT Presentation

orchestra ng containers with consul and terraform
SMART_READER_LITE
LIVE PREVIEW

Orchestra)ng Containers with Consul and Terraform Mitchell - - PowerPoint PPT Presentation

Orchestra)ng Containers with Consul and Terraform Mitchell Hashimoto @mitchellh ORCHESTRATION? Why is it needed? What is it? ORCHESTRATION Do some set of ac)ons, to a set of things, in a


slide-1
SLIDE 1

Orchestra)ng ¡Containers ¡ with ¡Consul ¡and ¡Terraform

slide-2
SLIDE 2

@mitchellh

Mitchell ¡Hashimoto

slide-3
SLIDE 3
slide-4
SLIDE 4

ORCHESTRATION? ¡

Why ¡is ¡it ¡needed? ¡What ¡is ¡it?

slide-5
SLIDE 5

ORCHESTRATION

  • Do ¡some ¡set ¡of ¡ac)ons, ¡to ¡a ¡set ¡of ¡things,


in ¡a ¡set ¡order. ¡

  • Ul$mate ¡goal: ¡safely ¡deliver ¡applica)ons ¡at ¡scale
slide-6
SLIDE 6

PROBLEMS ¡CONTAINERS ¡SOLVE

Packaging Image Storage Execution

slide-7
SLIDE 7

PROBLEMS ¡CONTAINERS ¡SOLVE

Packaging Image Storage Execution Docker Image Docker Registry Docker Daemon

slide-8
SLIDE 8

A ¡LOT ¡OF ¡OTHER ¡PIECES

  • Infrastructure ¡lifecycle ¡and ¡provisioning ¡
  • Monitoring ¡
  • Service ¡discovery ¡
  • Service ¡configura)on ¡
  • Security/Iden)ty ¡
  • Deployment ¡and ¡applica)on ¡lifecycle
slide-9
SLIDE 9

INFRASTRUCTURE

DC DNS Database CDN

slide-10
SLIDE 10

INFRASTRUCTURE

  • Container ¡hosts ¡
  • Storage ¡
  • Network ¡
  • External ¡services
slide-11
SLIDE 11

INFRASTRUCTURE

  • Crea)on, ¡update, ¡destroy ¡
  • Crea)on ¡is ¡easy ¡
  • Update ¡is ¡hard ¡
  • Update ¡with ¡minimal ¡down)me ¡is ¡hardest ¡
  • Has ¡its ¡own ¡lifecycle ¡events: ¡canary ¡infrastructure


changes, ¡rolling, ¡etc. ¡

slide-12
SLIDE 12

?

WEB ¡1 WEB ¡2 WEB ¡N

MONITORING

slide-13
SLIDE 13

MONITORING

  • Level ¡of ¡monitoring: ¡node, ¡container, ¡service ¡
  • Propaga)on ¡of ¡informa)on ¡
  • U)lity ¡of ¡the ¡informa)on ¡in ¡other ¡

  • rchestra)on ¡ac)ons
slide-14
SLIDE 14

SERVICE ¡DISCOVERY ¡AND ¡CONFIG

  • Where ¡is ¡service ¡foo? ¡
  • Run)me ¡configura)on ¡of ¡a ¡service


(especially ¡in ¡an ¡immutable ¡world) ¡

  • All ¡of ¡the ¡above ¡at ¡the ¡speed ¡of ¡containers
slide-15
SLIDE 15

SECURITY

  • Iden)ty ¡for ¡service ¡to ¡service ¡communica)on ¡
  • Storage ¡and ¡retrieval ¡of ¡secrets ¡
slide-16
SLIDE 16

APPLICATION ¡LIFECYCLE

  • Canary, ¡Rolling, ¡Blue/Green ¡
  • Create ¡before ¡destroy ¡
  • Triggering ¡a ¡deploy ¡(communica)on) ¡
  • Monitoring ¡a ¡deploy
slide-17
SLIDE 17

LIVING ¡WITH ¡LEGACY

  • Non-­‑container ¡to ¡container ¡isn’t ¡atomic ¡
  • Orchestra)on ¡needs ¡to ¡include ¡non-­‑containerized ¡systems ¡
  • Time ¡period ¡for ¡this ¡is ¡probably ¡years ¡
  • What ¡about ¡a ¡post-­‑container ¡world?
slide-18
SLIDE 18

AN ¡OLD ¡PROBLEM ¡

It ¡all ¡should ¡sound ¡familiar

slide-19
SLIDE 19

AN ¡OLD ¡PROBLEM

  • “Orchestra)on ¡problems” ¡not ¡caused ¡by ¡containers ¡
  • Higher ¡density/speed ¡reveals ¡and ¡exacerbates ¡problems ¡
  • New ¡aspects: ¡public ¡cloud, ¡growing ¡external ¡


service ¡footprint ¡

  • These ¡orchestra)on ¡problems ¡existed ¡yesterday, ¡


exist ¡today, ¡and ¡will ¡exist ¡tomorrow, ¡in ¡slightly
 different ¡forms

slide-20
SLIDE 20

SOLUTIONS ¡TO ¡LAST

Infrastructure ¡lifecycle, ¡service ¡discovery, ¡
 monitoring, ¡and ¡orchestraMon ¡at ¡scale
 for ¡all ¡infrastructures. ¡

slide-21
SLIDE 21

terraform.io

slide-22
SLIDE 22

Build, ¡combine, ¡and ¡launch ¡ infrastructure ¡safely ¡and ¡efficiently.

terraform.io

slide-23
SLIDE 23

What ¡If ¡I ¡asked ¡you ¡to… ¡

  • create ¡a ¡completely ¡isolated ¡second ¡environment ¡to ¡run ¡an ¡applica)on ¡

(staging, ¡QA, ¡dev, ¡etc.)? ¡

  • deploy ¡or ¡update ¡a ¡complex ¡applica)on? ¡ ¡
  • document ¡how ¡our ¡infrastructure ¡is ¡architected? ¡ ¡
  • delegate ¡some ¡ops ¡to ¡smaller ¡teams? ¡(Core ¡IT ¡vs. ¡App ¡IT)
slide-24
SLIDE 24

What ¡If ¡I ¡asked ¡you ¡to… ¡

  • create ¡a ¡completely ¡isolated ¡second ¡environment ¡to ¡run ¡an ¡applica)on ¡

(staging, ¡QA, ¡dev, ¡etc.)? ¡One ¡command. ¡

  • deploy ¡a ¡complex ¡new ¡applica)on? ¡Code ¡it, ¡diff ¡it, ¡pull ¡request. ¡
  • update ¡an ¡exis)ng ¡complex ¡applica)on? ¡Code ¡it, ¡diff ¡it, ¡pull ¡request. ¡
  • document ¡how ¡our ¡infrastructure ¡is ¡architected? ¡Read ¡the ¡code. ¡
  • delegate ¡some ¡ops ¡to ¡smaller ¡teams? ¡(Core ¡IT ¡vs. ¡App ¡IT) ¡Modules, ¡

code ¡reviews.

slide-25
SLIDE 25

Terraform

  • Create ¡infrastructure ¡with ¡code: ¡servers, ¡load ¡balancers, ¡databases, ¡email ¡

providers, ¡etc. ¡ ¡

  • One ¡command ¡to ¡create, ¡update ¡infrastructure. ¡
  • Preview ¡changes ¡to ¡infrastructure, ¡save ¡diffs. ¡ ¡
  • Use ¡code ¡+ ¡diffs ¡to ¡treat ¡infrastructure ¡change ¡just ¡like ¡code ¡change: ¡

make ¡a ¡pull ¡request, ¡show ¡the ¡differences, ¡review ¡it, ¡and ¡accept. ¡ ¡

  • Break ¡infrastructure ¡into ¡modules ¡to ¡encourage/allow ¡teamwork ¡without ¡

risking ¡stability. ¡

slide-26
SLIDE 26

Infrastructure ¡as ¡Code

DigitalOcean ¡Droplet ¡with ¡DNS ¡in ¡DNSimple

resource "digitalocean_droplet" "web" { name = "tf-web" size = "512mb" image = "centos-5-8-x32" region = "sfo1" } resource "dnsimple_record" "hello" { domain = "example.com" name = "test" value = "${digitalocean_droplet.web.ipv4_address}" type = "A" }

slide-27
SLIDE 27

Infrastructure ¡as ¡Code

DigitalOcean ¡Droplet ¡with ¡DNS ¡in ¡DNSimple

resource "digitalocean_droplet" "web" { name = "tf-web" size = "512mb" image = "centos-5-8-x32" region = "sfo1" } resource "dnsimple_record" "hello" { domain = "example.com" name = "test" value = "${digitalocean_droplet.web.ipv4_address}" type = "A" }

slide-28
SLIDE 28

Infrastructure ¡as ¡Code

DigitalOcean ¡Droplet ¡with ¡DNS ¡in ¡DNSimple

resource "digitalocean_droplet" "web" { name = "tf-web" size = "512mb" image = "centos-5-8-x32" region = "sfo1" } resource "dnsimple_record" "hello" { domain = "example.com" name = "test" value = "${digitalocean_droplet.web.ipv4_address}" type = "A" }

slide-29
SLIDE 29

Infrastructure ¡as ¡Code

DigitalOcean ¡Droplet ¡with ¡DNS ¡in ¡DNSimple

resource "digitalocean_droplet" "web" { name = "tf-web" size = "512mb" image = "centos-5-8-x32" region = "sfo1" } resource "dnsimple_record" "hello" { domain = "example.com" name = "test" value = "${digitalocean_droplet.web.ipv4_address}" type = "A" }

slide-30
SLIDE 30

Infrastructure ¡as ¡Code

  • Human ¡friendly ¡config, ¡JSON ¡compa)ble ¡
  • Text ¡format ¡makes ¡it ¡version-­‑able, ¡VCS-­‑friendly ¡
  • Declara)ve ¡
  • Infrastructure ¡as ¡code ¡on ¡a ¡level ¡not ¡before ¡possible
slide-31
SLIDE 31

Zero ¡to ¡Done ¡in ¡One ¡Command

Terraform ¡Apply

$ terraform apply digitalocean_droplet.web: Creating… dnsimple_record.hello: Creating… Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

slide-32
SLIDE 32

Zero ¡to ¡Done ¡in ¡One ¡Command

  • Idempotent ¡
  • Highly ¡parallelized ¡
  • Will ¡only ¡do ¡what ¡the ¡plan ¡says
slide-33
SLIDE 33

Safely ¡Change/Iterate

Terraform ¡Plan

+ digitalocean_droplet.web backups: "" => "<computed>" image: "" => "centos-5-8-x32" ipv4_address: "" => "<computed>" ipv4_address_private: "" => "<computed>" name: "" => "tf-web" private_networking: "" => "<computed>" region: "" => "sfo1" size: "" => "512mb" status: "" => "<computed>" + dnsimple_record.hello domain: "" => "example.com" domain_id: "" => "<computed>" hostname: "" => "<computed>" name: "" => "test" priority: "" => "<computed>" ttl: "" => "<computed>" type: "" => "A" value: "" => "${digitalocean_droplet.web.ipv4_address}"

slide-34
SLIDE 34

Safely ¡Change/Iterate

Terraform ¡Plan

+ digitalocean_droplet.web backups: "" => "<computed>" image: "" => "centos-5-8-x32" ipv4_address: "" => "<computed>" ipv4_address_private: "" => "<computed>" name: "" => "tf-web" private_networking: "" => "<computed>" region: "" => "sfo1" size: "" => "512mb" status: "" => "<computed>" + dnsimple_record.hello domain: "" => "example.com" domain_id: "" => "<computed>" hostname: "" => "<computed>" name: "" => "test" priority: "" => "<computed>" ttl: "" => "<computed>" type: "" => "A" value: "" => "${digitalocean_droplet.web.ipv4_address}"

slide-35
SLIDE 35

Safely ¡Change/Iterate

Terraform ¡Plan

+ digitalocean_droplet.web backups: "" => "<computed>" image: "" => "centos-5-8-x32" ipv4_address: "" => "<computed>" ipv4_address_private: "" => "<computed>" name: "" => "tf-web" private_networking: "" => "<computed>" region: "" => "sfo1" size: "" => "512mb" status: "" => "<computed>" + dnsimple_record.hello domain: "" => "example.com" domain_id: "" => "<computed>" hostname: "" => "<computed>" name: "" => "test" priority: "" => "<computed>" ttl: "" => "<computed>" type: "" => "A" value: "" => "${digitalocean_droplet.web.ipv4_address}"

slide-36
SLIDE 36

Safely ¡Change/Iterate

  • Plan ¡shows ¡you ¡what ¡will ¡happen ¡
  • Save ¡plans ¡to ¡guarantee ¡what ¡will ¡happen ¡
  • Plans ¡show ¡reasons ¡for ¡certain ¡ac)ons ¡(such ¡as ¡re-­‑create) ¡
  • Prior ¡to ¡Terraform: ¡Operators ¡had ¡to ¡“divine” ¡change ¡ordering, ¡

paralleliza)on, ¡rollout ¡effect.

slide-37
SLIDE 37

Lots ¡more ¡features…

  • Modules ¡for ¡knowledge ¡sharing, ¡reusable ¡components ¡
  • Remote ¡state ¡for ¡resource ¡sharing ¡
  • Targeted ¡applies ¡to ¡limit ¡effect ¡of ¡any ¡change ¡
  • Lifecycle ¡management ¡
  • Custom ¡plugins ¡are ¡simple
slide-38
SLIDE 38

Workflow

  • Make ¡code ¡changes ¡
  • `terraform ¡plan` ¡
  • Pull ¡request ¡with ¡code ¡changes ¡+ ¡plan ¡to ¡make ¡changes ¡
  • Review ¡and ¡merge ¡
  • `terraform ¡apply ¡pr1234.jplan`
slide-39
SLIDE 39

Terraform ¡with ¡Containers

Terraform ¡with ¡Docker

# Configure the Docker provider provider "docker" { host = "tcp://127.0.0.1:1234/" } # Create a container resource "docker_container" "foo" { image = "${docker_image.ubuntu.latest}" name = "foo" } resource "docker_image" "ubuntu" { name = "ubuntu:latest" }

slide-40
SLIDE 40

Terraform ¡with ¡Containers

Terraform ¡with ¡Docker

# Configure the Docker provider provider "docker" { host = "tcp://127.0.0.1:1234/" } # Create a container resource "docker_container" "foo" { image = "${docker_image.ubuntu.latest}" name = "foo" } resource "docker_image" "ubuntu" { name = "ubuntu:latest" }

slide-41
SLIDE 41

Terraform ¡with ¡Containers

Terraform ¡with ¡Docker

# Configure the Docker provider provider "docker" { host = "tcp://127.0.0.1:1234/" } # Create a container resource "docker_container" "foo" { image = "${docker_image.ubuntu.latest}" name = "foo" } resource "docker_image" "ubuntu" { name = "ubuntu:latest" }

slide-42
SLIDE 42

Terraform ¡with ¡Containers

Terraform ¡with ¡Docker

# Configure the Docker provider provider "docker" { host = “tcp://127.0.0.1:1234/" alias = “foo” } # Create a container resource "docker_container" "foo" { image = "${docker_image.ubuntu.latest}" name = “foo” provider = “docker.foo” }

slide-43
SLIDE 43

Terraform ¡with ¡Containers

Terraform ¡with ¡Docker

# Configure the Docker provider provider "docker" { host = “tcp://127.0.0.1:1234/" alias = “foo” } # Create a container resource "docker_container" "foo" { image = "${docker_image.ubuntu.latest}" name = “foo” provider = “docker.foo” }

slide-44
SLIDE 44

Terraform ¡with ¡Containers

Terraform ¡with ¡Docker

# Create a container resource "docker_container" "foo" { image = "${docker_image.ubuntu.latest}" name = “foo” host = “tcp://127.0.0.1:1234/“ }

slide-45
SLIDE 45

Terraform ¡with ¡Containers

Terraform ¡with ¡Docker

# Create a container resource "docker_container" "foo" { image = "${docker_image.ubuntu.latest}" name = “foo” host = “tcp://127.0.0.1:1234/“ }

slide-46
SLIDE 46

Terraform ¡with ¡Containers

  • Manage ¡both ¡the ¡underlying ¡infrastructure ¡and ¡applica)on-­‑level ¡

containers ¡

  • Inherit ¡lifecycle ¡management ¡features ¡of ¡Terraform ¡
  • Single ¡host ¡assign ¡+ ¡schedulers
slide-47
SLIDE 47

consul.io

slide-48
SLIDE 48

Service ¡discovery, ¡configuraMon, ¡and ¡

  • rchestraMon ¡made ¡easy. ¡Distributed, ¡

highly ¡available, ¡and ¡datacenter-­‑aware.

slide-49
SLIDE 49

Ques)ons ¡that ¡Consul ¡Answers

  • Where ¡is ¡the ¡service ¡foo? ¡(ex. ¡Where ¡is ¡the ¡database?) ¡
  • What ¡is ¡the ¡health ¡status ¡of ¡service ¡foo? ¡
  • What ¡is ¡the ¡health ¡status ¡of ¡the ¡machine/node ¡foo? ¡
  • What ¡is ¡the ¡list ¡of ¡all ¡currently ¡running ¡machines? ¡
  • What ¡is ¡the ¡configura)on ¡of ¡service ¡foo? ¡
  • Is ¡anyone ¡else ¡currently ¡performing ¡opera)on ¡foo? ¡
slide-50
SLIDE 50

Service ¡Discovery ¡ Where ¡is ¡service ¡foo?

slide-51
SLIDE 51

Service ¡Discovery

Service ¡Discovery ¡via ¡DNS ¡or ¡HTTP

$ dig web-frontend.service.consul. +short 10.0.3.89 10.0.1.46 $ curl http://localhost:8500/v1/catalog/service/web-frontend [{ “Node”: “node-e818f1”, “Address”: “10.0.3.89”, “ServiceID”: “web-frontend”, … }]

slide-52
SLIDE 52

Service ¡Discovery

  • DNS ¡is ¡legacy-­‑friendly. ¡No ¡applica)on ¡changes ¡required. ¡
  • HTTP ¡returns ¡rich ¡metadata. ¡
  • Discover ¡both ¡internal ¡and ¡external ¡services ¡


(such ¡as ¡service ¡providers)

slide-53
SLIDE 53

Failure ¡Detection ¡ Is ¡service ¡foo ¡healthy/available?

slide-54
SLIDE 54

Failure ¡Detec)on

slide-55
SLIDE 55

Failure ¡Detec)on

  • DNS ¡won’t ¡return ¡non-­‑healthy ¡services ¡or ¡nodes. ¡
  • HTTP ¡has ¡endpoints ¡to ¡list ¡health ¡state ¡of ¡catalog.
slide-56
SLIDE 56

Key/Value ¡Storage ¡

What ¡is ¡the ¡config ¡of ¡service ¡foo?

slide-57
SLIDE 57

Key/Value ¡Storage

Semng ¡and ¡Gemng ¡a ¡Key

$ curl –X PUT –d ‘bar’ http://localhost:8500/v1/kv/foo true $ curl http://localhost:8500/v1/kv/foo?raw bar

slide-58
SLIDE 58

Key/Value ¡Storage

  • Highly ¡available ¡storage ¡of ¡configura)on. ¡
  • Turn ¡knobs ¡without ¡big ¡configura)on ¡management ¡process. ¡
  • Watch ¡keys ¡(long ¡poll) ¡for ¡changes ¡
  • ACLs ¡on ¡key/value ¡to ¡protect ¡sensi)ve ¡informa)on
slide-59
SLIDE 59

Multi-­‑Datacenter

slide-60
SLIDE 60

Mul)-­‑Datacenter

Service ¡Discovery

$ dig web-frontend.singapore.service.consul. +short 10.3.3.33 10.3.1.18 $ dig web-frontend.germany.service.consul. +short 10.7.3.41 10.7.1.76

slide-61
SLIDE 61

Mul)-­‑Datacenter

Semng ¡and ¡Gemng ¡a ¡Key

$ curl http://localhost:8500/v1/kv/foo?raw&dc=asia true $ curl http://localhost:8500/v1/kv/foo?raw&dc=eu false

slide-62
SLIDE 62

Mul)-­‑Datacenter

  • Local ¡by ¡default ¡
  • Can ¡query ¡other ¡datacenters ¡however ¡you ¡may ¡need ¡to ¡
  • Can ¡view ¡all ¡datacenters ¡within ¡one ¡UI
slide-63
SLIDE 63

Orchestration ¡ Events, ¡Exec, ¡Locks, ¡Watches

slide-64
SLIDE 64

Events, ¡Exec, ¡Watches

Dispatching ¡Custom ¡Events

$ consul event deploy 6DF7FE … $ consul watch -type event -name deploy /usr/bin/deploy.sh … $ consul exec -service web /usr/bin/deploy.sh …

slide-65
SLIDE 65

Events, ¡Exec, ¡Watches

  • Powerful ¡orchestra)on ¡tools ¡
  • Pros/cons ¡to ¡each ¡approach, ¡use ¡the ¡right ¡tool ¡for ¡the ¡job ¡
  • All ¡approaches ¡proven ¡to ¡scale ¡to ¡thousands ¡of ¡agents
slide-66
SLIDE 66

Locks

Dispatching ¡Custom ¡Events

$ consul lock ./deploy.sh … $ consul lock -n=5 ./deploy.sh …

slide-67
SLIDE 67

Locks

  • Distributed ¡lock ¡
  • Can ¡have ¡up ¡to ¡n ¡acquisi)ons ¡(semaphore) ¡
  • Primi)ve ¡to ¡make ¡redundant ¡but ¡serial ¡services
slide-68
SLIDE 68

Opera)onal ¡Bullet ¡Points

  • Leader ¡elec)on ¡via ¡Ran ¡
  • Gossip ¡protocol ¡for ¡aliveness ¡
  • Three ¡consistency ¡models: ¡default, ¡consistent, ¡and ¡stale ¡
  • Encryp)on, ¡ACLs ¡available ¡
  • Real ¡world ¡usage ¡to ¡thousands ¡of ¡agents ¡per ¡datacenter
slide-69
SLIDE 69

Consul ¡with ¡Containers

  • Run ¡in ¡or ¡outside ¡the ¡container ¡
  • Run)me ¡configura)on ¡vs. ¡build)me ¡configura)on ¡
  • Discover ¡non-­‑container ¡services, ¡plus ¡transparent ¡change ¡if/when ¡

they ¡become ¡containers ¡

  • Speed ¡and ¡scalability ¡of ¡Consul ¡very ¡easily ¡ready ¡for ¡“container ¡scale” ¡

as ¡well ¡as ¡future ¡scale

slide-70
SLIDE 70

Thanks!

Q U E S T I O N S ?