Top Banner
Service Discovery and Puppet Marc Cluet
75

Service discovery and puppet

Apr 14, 2017

Download

Technology

Marc Cluet
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Service discovery and puppet

Service Discovery and PuppetMarc Cluet

Page 2: Service discovery and puppet

Who am I?

@lynxman

Engineer based in London

Co-Founder of Ukon Cherry

Working at TrainLine

19 years of experience as a SysAdmin

Founding member of Juju and MAAS while at Canonical

Built a DevOps Engineering Team at Rackspace

Been DevOps’in for the last 7 years

2

Page 3: Service discovery and puppet

Meet other people in London!

3

http://www.meetup.com/London-DevOps/

Page 4: Service discovery and puppet

Running in the Cloud?

4

https://www.flickr.com/photos/pontla/11879018534/

Page 5: Service discovery and puppet

The Problem

Cloud is Hard!

Old Style DNS

TTL a problem for auto-scaling

Non-reactive health checks

Where do I keep my metadata?

5

https://www.flickr.com/photos/qchristopher/5038229030/

Page 6: Service discovery and puppet

The Solution!You were expecting this weren't you

6

Page 7: Service discovery and puppet

Service Discovery

Automatically define your services

Active Health Checking

Dynamically updated service lists

Can be DNS accessible (if needed)

API accessible (win!)

7

https://www.flickr.com/photos/marknye/12992319144/

Page 8: Service discovery and puppet

Service Discovery

8

Service Publication

Service Node A

Service Node B

Service Node C

Page 9: Service discovery and puppet

Service Discovery

9

Service Publication

Service Node A

Health Check

Discovery Agent

Discovery Agent

Service Node B

Health Check

Page 10: Service discovery and puppet

Service Discovery

10

Service Publication

Service Node A

Health Check

Discovery Agent

Discovery Agent

Service Node B

Health Check

Page 11: Service discovery and puppet

Service Discovery

11

Service Publication

Service Node A

Health Check

Discovery Agent

Discovery Agent

Service Node B

Health Check

Page 12: Service discovery and puppet

Service Discovery

12

Service Publication

Service Node A

Health Check

Discovery Agent

Discovery Agent

Service Node B

Health Check

Page 13: Service discovery and puppet

Amazeballs!

13

https://www.flickr.com/photos/neilmartin/31519343/

Page 14: Service discovery and puppet

Amazeballs!

14

https://www.flickr.com/photos/neilmartin/31519343/

Page 15: Service discovery and puppet

Service Discovery

15

Service Node A

Service: web

10.10.10.1 10.10.10.2 10.10.10.3

Service Node B

Service Node C

Page 16: Service discovery and puppet

Service Discovery

16

Service Node A

Service: web

10.10.10.1 10.10.10.2 10.10.10.3

Service Node B

Service Node C

Page 17: Service discovery and puppet

Service Discovery

17

Service Node A

Service: web

10.10.10.1 10.10.10.2 10.10.10.3

Service Node B

Service Node C

Page 18: Service discovery and puppet

Amazeballs!

18

https://www.flickr.com/photos/neilmartin/31519343/

Page 19: Service discovery and puppet

Service Discovery

19

Agent Master Agent Agent Agent Agent

Agent Agent Agent Agent Master Agent

Agent Agent Master Agent Agent Agent

Agent Agent Agent Agent Agent Agent

Page 20: Service discovery and puppet

Service Discovery

20

Agent Master Agent Agent Agent Agent

Agent Agent Agent Agent Master Agent

Agent Agent Master Agent Agent Agent

Agent Agent Agent Agent Agent Agent

Page 21: Service discovery and puppet

Service Discovery

21

Agent Master Agent Agent Agent Agent

Agent Agent Agent Agent Master Agent

Agent Agent Master Agent Agent Agent

Agent Agent Agent Agent Agent Agent

Page 22: Service discovery and puppet

Service Discovery

22

Agent Master Agent Agent Agent Agent

Agent Agent Agent Agent Master Agent

Agent Agent Master Agent Agent

Agent Agent Agent Agent Agent Agent

Page 23: Service discovery and puppet

Service Discovery

23

Agent Master Agent Agent Agent Agent

Agent Agent Agent Agent Master Agent

Agent Agent Master Agent Agent

Agent Agent Agent Agent Agent Agent

! !

!

Page 24: Service discovery and puppet

Service Discovery

24

Agent Master Agent Agent Agent Agent

Agent Agent Agent Agent Master Agent

Agent Agent Master Agent Agent Agent

Agent Agent Agent Agent Agent Agent

Page 25: Service discovery and puppet

Amazeballs!

25

https://www.flickr.com/photos/neilmartin/31519343/

Page 26: Service discovery and puppet

Service Discovery SolutionsChoices!

26

Page 27: Service discovery and puppet

Service Discovery Solutions

CoreOS Fleet Uses the sidekick

model, uses separate agents to orchestrate

service discovery.

Kubernetes Service All pods declare services to be

discoverable by the cluster.

27

Consul All services are declared by the

agents, the agents themselves are

responsible.

Page 28: Service discovery and puppet

Service Discovery Solutions

CoreOS Fleet API publication

k/v Strongly Consistent

Container checks

Kubernetes Service API publication

Container checks

Auto-Heal

28

Consul API + DNS publication

k/v Strongly Consistent

Host + Service checks

Puppet modulePuppet module Hiera access

Puppet module Hiera access

Page 29: Service discovery and puppet

Service Discovery Solutions

29

Page 30: Service discovery and puppet

What is Consul?

It's a Service Discovery System (duh!)

Service Publications (DNS + API)

k/v Storage (strongly consistent)

Health Checks

With encryption! (whaaaaaat)

30

Page 31: Service discovery and puppet

What is Consul?

31

Page 32: Service discovery and puppet

Consul Concepts

Datacenter

Node

Service

Health Check

Watches

ACLs

32

Page 33: Service discovery and puppet

Consul Architecture

33

Consul Master

Consul Master

Consul Master

Page 34: Service discovery and puppet

Consul Architecture

34

Consul Master

Consul Master

Consul Master

Consul AgentConsul AgentConsul AgentConsul AgentConsul AgentConsul AgentConsul Agent

Page 35: Service discovery and puppet

Consul Architecture

35

Consul Master

Consul Master

Consul Master

Consul AgentConsul AgentConsul AgentConsul AgentConsul AgentConsul AgentConsul Agent

Consul Master

WAN DC

Page 36: Service discovery and puppet

Consul DNS publisher

Port 8600

Use dnsmasq:

server=/consul/127.0.0.1#8600

36

Page 37: Service discovery and puppet

Consul DNS publisher

service name: web

zone: yourDC

<servicename>.service.<zone>.consul

web.service.yourDC.consul

37

Page 38: Service discovery and puppet

Consul Catalog API

API http://localhost:8500

/v1/catalog/

/v1/catalog/datacenters/

/v1/catalog/nodes/

/v1/catalog/services/<servicename>

/v1/catalog/service/<name>

/v1/catalog/node/<nodename>

38

Page 39: Service discovery and puppet

Consul Health Checks

{

"check": {

"id": "mem-util",

"name": "Memory utilization",

"script": "/usr/local/bin/check_mem.py",

"interval": "10s"

}

}

39

Page 40: Service discovery and puppet

Consul Health Checks

40

Server

Page 41: Service discovery and puppet

Consul Health Checks

41

Server

Memory Disk CPU Load Logs

Page 42: Service discovery and puppet

Consul Health Checks

42

Server

Service Service

Page 43: Service discovery and puppet

Consul Restful API

API http://localhost:8500

/v1/kv/

/v1/agent/

/v1/catalog/

/v1/health/

/v1/session/

/v1/acl/

/v1/status/

43

Page 44: Service discovery and puppet

Consul Restful API

API http://localhost:8500

/v1/kv/

/v1/agent/

/v1/catalog/

/v1/health/

/v1/session/

/v1/acl/

/v1/status/

44

Page 45: Service discovery and puppet

Now comes the Puppet stuff!All of this applied!

45

Page 46: Service discovery and puppet

You can do all this after the talk

https://github.com/lynxman/consul-first-steps

46

https://www.flickr.com/photos/hortlander/6245707871/

Page 47: Service discovery and puppet

Puppet + Consul

47

https://www.flickr.com/photos/hortlander/6245707871/in/

You can integrate at several levels

Puppet Module

KyleAnderson-consul

Hiera

lynxman-hiera_consul

Page 48: Service discovery and puppet

Puppet + Consul

48

https://www.flickr.com/photos/hortlander/6245707871/in/

You can integrate at several levels

k/v access

venmo-consulr

Templates with Consul

ghdbaston-consul_template

Page 49: Service discovery and puppet

Puppet Module - Install

49

https://www.flickr.com/photos/hortlander/6245707871/in/

Puppet Forge makes it very easy to install

$ puppet module install KyleAnderson-consul

Page 50: Service discovery and puppet

Puppet Module - Dnsmasq Install

50

https://www.flickr.com/photos/hortlander/6245707871/in/

$ puppet module install saz-dnsmasq

include dnsmasq

dnsmasq::conf { 'consul':

ensure => present,

content => 'server=/consul/127.0.0.1#8600',

}

Page 51: Service discovery and puppet

Puppet Module - Health Checks

51

https://www.flickr.com/photos/hortlander/6245707871/in/

consul::check { 'disk_space':

script => 'check_disk -w 5% -c 1%',

interval => '30s',

}

Page 52: Service discovery and puppet

Puppet Module - Services

52

https://www.flickr.com/photos/hortlander/6245707871/in/

consul::service { 'nginx':

port => '80',

checks => [

{

script => 'check_http -H localhost -w 20 -c 60',

interval => '30s',

},

],

}

Page 53: Service discovery and puppet

Puppet Hiera

53

Puppet Hiera Consul

Hiera Yaml

Page 54: Service discovery and puppet

Puppet Hiera Module - Install

54

https://www.flickr.com/photos/hortlander/6245707871/in/

Puppet Forge makes it very easy to install

$ puppet module install lynxman-hiera_consul

Page 55: Service discovery and puppet

Puppet Hiera Module - Config

55

https://www.flickr.com/photos/hortlander/6245707871/in/

:backends:

- yaml

- consul

:yaml:

:datadir: /etc/puppetlabs/hieradata

:consul:

:host: 127.0.0.1

:port: 8500

:failure: graceful

:paths:

- /v1/catalog/service

- /v1/catalog/node

Page 56: Service discovery and puppet

Puppet Hiera Module - Config

56

https://www.flickr.com/photos/hortlander/6245707871/in/

:consul:

:host: 127.0.0.1

:port: 8500

:failure: graceful

:paths:

- /v1/catalog/service

- /v1/catalog/node

Page 57: Service discovery and puppet

Puppet Hiera Module - Arrays

57

https://www.flickr.com/photos/hortlander/6245707871/in/

notice('Generating rabbitmq cluster members based on Consul information')

$consul_service_array = hiera('rabbitmq',[])

$mq_cluster_nodes = consul_info($consul_service_array, 'Address')

notice("Result: ${mq_cluster_nodes}")

Page 58: Service discovery and puppet

Puppet Hiera Module - Arrays

58

https://www.flickr.com/photos/hortlander/6245707871/in/

notice("Generating neo4j_ha cluster members based on Consul information")

$consul_service_array = hiera('neo4j_ha',[])

$consul_fields = [ 'Address', 'ServicePort' ]

$consul_ha_initial_hosts = consul_info($consul_service_array, $consul_fields, ':')

$ha_initial_hosts = join($consul_ha_initial_hosts, ',')

notice("Result: ${ha_initial_hosts}")

Page 59: Service discovery and puppet

Puppet Hiera Module - Accessing the k/v

59

https://www.flickr.com/photos/hortlander/6245707871/in/

:consul:

:host: 127.0.0.1

:port: 8500

:failure: graceful

:paths:

- /v1/kv/

Page 60: Service discovery and puppet

Puppet Hiera Module - Accessing the k/v

60

https://www.flickr.com/photos/hortlander/6245707871/in/

:consul:

:host: 127.0.0.1

:port: 8500

:failure: graceful

:paths:

- /v1/kv/mystuff/

Page 61: Service discovery and puppet

Puppet Hiera Module - Accessing the k/v

61

https://www.flickr.com/photos/hortlander/6245707871/in/

:consul:

:host: 127.0.0.1

:port: 8500

:failure: graceful

:paths:

- "/v1/kv/%{env}/"

Page 62: Service discovery and puppet

Puppet SecurityDon't get your a** on the line!

62

Page 63: Service discovery and puppet

Puppet Security - Github

63

https://www.flickr.com/photos/hortlander/6245707871/in/

$ git commit -m "All my passwords"

$ git push

Page 64: Service discovery and puppet

Puppet Hiera Module - Arrays

64

https://www.flickr.com/photos/hortlander/6245707871/in/

https://www.flickr.com/photos/tomukas/3554360505/

Page 65: Service discovery and puppet

Puppet Security - Hiera Modules

65

https://www.flickr.com/photos/hortlander/6245707871/in/

hiera-eyaml

hiera-gpg

Page 66: Service discovery and puppet

Puppet Security - Hiera

66

Puppet Hiera Consul

Hiera eyaml

Page 67: Service discovery and puppet

Puppet Security - Module Install

67

https://www.flickr.com/photos/hortlander/6245707871/in/

Puppet Forge makes it very easy to install

$ puppet module install hiera-eyaml

Page 68: Service discovery and puppet

Puppet Security - Hiera eyaml

68

https://www.flickr.com/photos/hortlander/6245707871/in/

$ eyaml createkeys

keys/public_key.pkcs7.pem

keys/private_key.pkcs7.pem

Page 69: Service discovery and puppet

Puppet Security - Hiera eyaml

69

https://www.flickr.com/photos/hortlander/6245707871/in/

Usage: eyaml <subcommand>

Please use one of the following subcommands or help for more help:

createkeys, decrypt, edit, encrypt, recrypt, version

Page 70: Service discovery and puppet

Puppet Security - Hiera eyaml

70

https://www.flickr.com/photos/hortlander/6245707871/in/

mysecret: DEC::PKCS7[mypassword]!

Page 71: Service discovery and puppet

Puppet Security - Hiera eyaml

71

https://www.flickr.com/photos/hortlander/6245707871/in/

mysecret: ENC[PKCS7,MIIBmQYJKoZIhvcNAQcDoIIBijCCAYYCAQAxggEhMIIBHQIBADAFMAACAQEwDQYJKoZIhvcNAQEBBQAEggEAAikKizydVh0wXQrvtoMC7vM9NxfksqwOX2jtajDYMMJwXXP/5zKHjnnGmr+LSXFVkL52FuGentCdityjF0zZEvbZ2D95TWnRTinO9htteC8ZiwqpTeuNJkTJikOEEZvHbNlp6eX381ppKoatV1k0EmIHwsnqeRJN5T9TVScoXOb/1Fre4H7TxSvvaFqo02MWUBaKkWECoEu2PLiuXWEoiLrkDq8pxhjYADvGUJLWC8PUSWT/94075z5UKHYBQgLlFrzG+89Rhm5keTy/cuHsOK9d0nUScjd4m6duCEsvRT5SG/n6GwTEk/cDMqIuvAwNETv2fdepu4z5nR383zlngDBcBgkqhkiG9w0BBwEwHQYJYIZIAWUDBAEqBBAJCDkds8PbXeBUMZhFPxWTgDDH1pvUCbCLtWDNVFkW2yZ1NYF06RuqsSTxofHfMwajC+BSPcTu7heMKQnbKP/KE6o=]

Page 72: Service discovery and puppet

Puppet Security Extra time!This is beyond awesome

72

Page 73: Service discovery and puppet

Puppet Security - Extra

73

https://www.flickr.com/photos/hortlander/6245707871/in/

Page 74: Service discovery and puppet

Puppet Security - Extra

Friday, October 21 • 11:15am - 12:00pm

Using HashiCorp's Vault With Puppet

Seth Vargo, HashiCorp

74

Page 75: Service discovery and puppet