ServiceDiscoveryandPuppet
byMarcCluet(@lynxman)
PuppetCampLondonAutumn2015
Welcome!
https://www.flickr.com/photos/tjt195/108543101/
Engineer based in London
Co-Founder of Ukon Cherry
Contractor 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 6 years
WhoamI?
LondonDevOpsMeetup
https://www.flickr.com/photos/eypeeet/9059983915/
https://www.flickr.com/photos/pontla/11879018534/
Cloud is hard!
• Old style DNS
• TTL is a b*tch
• Health Checks
• Metadata Storage
TheProblem
TheSolution!
https://www.flickr.com/photos/bisgovuk/9191500878/
Automatically define your services
• Active Health Checking
• Dynamically updated service lists
• Can be DNS accessible (if needed)
• API accessible (win!)
ServiceDiscovery
ServiceDiscovery
Service
Publication
Service
Node A
Service
Node B
Service
Node C
ServiceDiscovery
Service
Publication
Service
Node A
Service
Node B
Health Check Health Check
Discovery AgentDiscovery Agent
ServiceDiscovery
Service
Publication
Service
Node A
Service
Node B
Health Check Health Check
Discovery AgentDiscovery Agent
ServiceDiscovery
Service
Publication
Service
Node A
Service
Node B
Health Check Health Check
Discovery AgentDiscovery Agent
ServiceDiscovery
Service
Publication
Service
Node A
Service
Node B
Health Check Health Check
Discovery AgentDiscovery Agent
https://www.flickr.com/photos/neilmartin/31519343/
https://www.flickr.com/photos/neilmartin/31519343/
ServiceDiscovery
Service
Node A
Service
Node C
Service
Node B
Service: web
10.10.10.1
10.10.10.2
10.10.10.3
ServiceDiscovery
Service
Node A
Service
Node C
Service
Node B
Service: web
10.10.10.1
10.10.10.2
10.10.10.3
ServiceDiscovery
Service
Node A
Service
Node C
Service
Node B
Service: web
10.10.10.1
10.10.10.2
10.10.10.3
https://www.flickr.com/photos/neilmartin/31519343/
ServiceDiscoverySolutions
ServiceDiscoverySolutions
ServiceDiscoverySolutions
ServiceDiscoverySolutions
API + DNS publication
k/v Strongly Consistent
Host + Service checks
API publication
k/v Consistent
Container checks
API publication
Container checks
Auto-Heal
Puppet module
Hiera access
Puppet module
Hiera access
Puppet module
ServiceDiscoverySolutions
It's a Service Discovery System (duh!)
• Service Publications (DNS + API)
• k/v Storage (strongly consistent)
• Health Checks
• With encryption! (whaaaaaat)
WhatisConsul?
Strongly Consistent!
WhatisConsul?
Datacenter
Node
Service
Health Check
ConsulConcepts
ConsulArchitecture
Consul Server
A
Consul Server
B
Consul Server
C
ConsulArchitecture
Consul Server
A
Consul Agent
Consul Server
B
Consul Server
C
Consul AgentConsul AgentConsul AgentConsul AgentConsul AgentConsul AgentConsul AgentConsul Agent
ConsulArchitecture
Consul Server
A
Consul Agent
Consul Server
B
Consul Server
C
Consul AgentConsul AgentConsul AgentConsul AgentConsul AgentConsul AgentConsul AgentConsul Agent
Consul Servers
Another DC
Port 8600
Use dnsmasq:
server=/consul/127.0.0.1#8600
ConsulDNSpublisher
service name: web
zone: eu-west-1
<servicename>.service.<zone>.consul
web.service.eu-west-1.consul
ConsulDNSpublisher
API http://localhost:8500
/v1/catalog/
/v1/catalog/datacenters/
/v1/catalog/nodes/
/v1/catalog/services/<servicename>
/v1/catalog/service/<name>
/v1/catalog/node/<nodename>
ConsulDNSpublisher
{
"check": {
"id": "mem-util",
"name": "Memory utilization",
"script": "/usr/local/bin/check_mem.py",
"interval": "10s"
}
}
ConsulHealthChecks
ConsulHealthChecks
Server
ConsulHealthChecks
Server
Memory
Disk
CPU
Load
Logs
ConsulHealthChecks
Server
ServiceService
/v1/kv/
/v1/agent/
/v1/catalog/
/v1/health/
/v1/session/
/v1/acl/
/v1/status/
ConsulRESTfulAPI
/v1/kv/
/v1/agent/
/v1/catalog/
/v1/health/
/v1/session/
/v1/acl/
/v1/status/
ConsulRESTfulAPI
Puppets!!!
https://www.flickr.com/photos/tjt195/108543101/
https://github.com/lynxman/consul-first-steps
Youcanfollowthis
Puppet+Consul
You can integrate at several levels
• Puppet Module
• KyleAnderson-consul
• Hiera
• lynxman-hiera_consul
Puppet+Consul
You can integrate at several levels
• k/v access
• venmo-consulr
• Templates with Consul
• ghdbaston-consul_template
PuppetModule-Install
Puppet Forge makes it very easy to install
$ puppet module install KyleAnderson-consul
PuppetModule-DNS
$ puppet module install saz-dnsmasq
include dnsmasq
dnsmasq::conf { 'consul':
ensure => present,
content => 'server=/consul/127.0.0.1#8600',
}
PuppetModule-NodeChecks
consul::check { 'disk_space':
script => '/usr/lib/nagios/plugins/check_disk
-w 5% -c 1% -x /run/lock -x /run/shm -x /run/user -x
/dev -x /run -x /sys/fs/cgroup',
interval => '30s',
}
PuppetModule-ServiceChecks
consul::service { 'nginx':
port => '80',
checks => [
{
script => "/usr/lib/nagios/plugins/check_http -H localhost
-w 20 -c 60 -t 20",
interval => '30s',
},
],
}
PuppetHiera
Puppet
yaml
Hiera
consul
PuppetModule-Install
Puppet Forge makes it very easy to install
$ puppet module install lynxman-hiera_consul
PuppetHiera-Config
:backends:
- yaml
- consul
:yaml:
:datadir: /etc/puppet/hieradata
:consul:
:host: 127.0.0.1
:port: 8500
:failure: graceful
:paths:
- /v1/catalog/service
- /v1/catalog/node
PuppetHiera-Config
:consul:
:host: 127.0.0.1
:port: 8500
:failure: graceful
:paths:
- /v1/catalog/service
- /v1/catalog/node
PuppetHiera-Arrays
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}")
PuppetHiera-Arrays
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}")
PuppetHiera-k/vaccess
Long live to the API!
:consul:
:host: 127.0.0.1
:port: 8500
:failure: graceful
:paths:
- /v1/kv/
PuppetHiera-k/vaccess
Long live to the API!
:consul:
:host: 127.0.0.1
:port: 8500
:failure: graceful
:paths:
- /v1/kv/web/
PuppetHiera-k/vaccess
Long live to the API!
:consul:
:host: 127.0.0.1
:port: 8500
:failure: graceful
:paths:
- "/v1/kv/%{env}/"
PuppetHiera
Puppet
yaml
Hiera
consul
Security
https://www.flickr.com/photos/wiredforsound23/5436792923/
PuppetSecurity
PuppetSecurity
git commit -m "All my passwords"
git push
https://www.flickr.com/photos/mach5/183670686/
https://www.flickr.com/photos/mach5/183670686/
https://www.flickr.com/photos/lockergnome/262487854/
PuppetSecurity
hiera-eyaml
hiera-gpg
PuppetHiera
Puppet
yaml
Hiera
eyaml
consul
Hieraeyaml
gem install hiera-eyaml
Hieraeyaml
$ eyaml createkeys
keys/public_key.pkcs7.pem
keys/private_key.pkcs7.pem
Hieraeyaml
Usage: eyaml <subcommand>
Please use one of the following
subcommands or help for more help:
createkeys, decrypt, edit, encrypt,
recrypt, version
Hieraeyaml
mysecret: DEC::PKCS7[mypassword]!
Hieraeyaml
mysecret:
ENC[PKCS7,MIIBmQYJKoZIhvcNAQcDoIIBijCCAYYCAQAxggEhMII
BHQIBADAFMAACAQEwDQYJKoZIhvcNAQEBBQAEggEAAikKizydVh0w
XQrvtoMC7vM9NxfksqwOX2jtajDYMMJwXXP/5zKHjnnGmr
+LSXFVkL52FuGentCdityjF0zZEvbZ2D95TWnRTinO9htteC8Ziwq
pTeuNJkTJikOEEZvHbNlp6eX381ppKoatV1k0EmIHwsnqeRJN5T9T
VScoXOb/
1Fre4H7TxSvvaFqo02MWUBaKkWECoEu2PLiuXWEoiLrkDq8pxhjYA
DvGUJLWC8PUSWT/94075z5UKHYBQgLlFrzG+89Rhm5keTy/
cuHsOK9d0nUScjd4m6duCEsvRT5SG/n6GwTEk/
cDMqIuvAwNETv2fdepu4z5nR383zlngDBcBgkqhkiG9w0BBwEwHQY
JYIZIAWUDBAEqBBAJCDkds8PbXeBUMZhFPxWTgDDH1pvUCbCLtWDN
VFkW2yZ1NYF06RuqsSTxofHfMwajC+BSPcTu7heMKQnbKP/KE6o=]
https://www.flickr.com/photos/rolandslakis/112038134/
https://www.flickr.com/photos/theeerin/2506959766/
EXTRATIME!
https://www.flickr.com/photos/nathaninsandiego/5134124956/
Vault$ vault write secret/foo value=bar
Success! Data written to: secret/foo
$ vault read secret/foo
Key Value
lease_id secret/foo/9c5f3cf1-1239-0160-4311-d6544fd1018c
lease_duration 2592000
value bar
$ vault delete secret/foo
Success! Deleted 'secret/foo'
Vault
$ vault read postgresql/creds/production
Key Value
lease_id postgresql/creds/production/8ade2cde-5081-
e3b7-af1a-3b9fb070df66
lease_duration 3600
password 56b43bc3-b285-4803-abdf-662d6a105bd0
username vault-root-1430141210-1847
https://www.flickr.com/photos/neilmartin/31519343/
Questions?
Follow me!
@lynxman

Puppet Camp London Fall 2015 - Service Discovery and Puppet