59
Cloud Infrastructure as Code Andrew Parker Puppet Labs @aparker42

Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Embed Size (px)

DESCRIPTION

And

Citation preview

Page 1: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Cloud Infrastructure

as Code

Andrew Parker

Puppet Labs

@aparker42

Page 2: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

In 1889

Page 3: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 4: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 5: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Tickets please

Page 6: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Eureka !

Page 7: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Herman's Invention

Page 8: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Herman, grows a Mustache

Page 9: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

The Tabulating Machine

Page 10: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Automation makes IT better!

Page 11: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 12: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 13: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 14: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 15: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 16: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 17: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 18: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 19: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 20: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 21: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 22: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Puppet

A language and infrastructure

Page 23: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Puppet Resources

• Describes the desired configuration state of

individual elements of the system being

managed

user { 'henrik': # A user named 'henrik'

ensure => present, # should exist

shell => '/bin/bash' # with this shell

}

Page 24: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Puppet Resources

package{ 'apache2': # A packaged named 'apache2'

ensure => present # should be installed

}

Page 25: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Puppet Language

• The Puppet Language has constructs to

– compose sets of resources into classes

– define order of operations on resources

– define custom resources

Page 26: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Common Pattern; Package, File,

Service

class webserver {

package{ 'apache2':

ensure => present

}

file { '/etc/apache2/apache2.conf':

content => template('apache2/apache2.erb'),

require => Package['apache2']

}

service { 'apache2':

ensure => running,

subscribe => File['/etc/apache2/apache2.conf']

}

}

Page 27: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Presto – a Web Server

• Now we can build a webserver with this:

node kermit.example.com {

include webserver

}

Page 28: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Infra == Code == Text

Page 29: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Infra == Code == Text

Page 30: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Infra == Code == Text

Page 31: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 32: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Cloud Infrastructure

(as Code)

Page 33: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Turtles All The Way Down

Page 34: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Turtles All The Way Down

Cloud

Page 35: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Google Compute Engine

• Express infrastructure as

– VM Instances

– Networks

– Firewalls

– Disks

Page 36: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Build your own?

puppet module install puppetlabs-gce_compute

Page 37: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

A Disk

gce_disk { 'mydisk':

ensure => present,

size_gb => '2'

}

Page 38: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

A Network

gce_network { 'mynetwork':

ensure => present,

gateway => '10.0.1.1',

range => '10.0.1.0/24'

}

Page 39: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

An Instance

gce_instance { 'myinstance':

ensure => present,

zone => 'us-central1-a',

machine => 'n1-standard-1',

image => "${images}/ubuntu-12-04-v20120621"

}

Page 40: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

New Pattern; Network, Firewall,

(Disk), Instance

class app_stack {

gce_network { 'appnet':

ensure => present,

range => '10.0.1.0/24'

} ->

gce_firewall { 'webhttp':

ensure => present,

allow => 'tcp:80',

network => 'appnet'

} ->

gce_instance { 'server1':

ensure => present,

network => 'appnet'

}

}

Page 41: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Turtles All The Way Down

Application

Cloud

Page 42: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Modules & Classes

gce_instance { 'myinstance':

ensure => present,

. . .

modules => [ 'puppetlabs-mysql',

'martasd/mediawiki',

. . .

],

enc_classes => {

mediawiki => {server_name => "$gce_external_ip"}

}

}

Page 43: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Turtles All The Way Down

Puppet

Cloud

Page 44: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Setting up a master

gce_instance { 'pe-master':

ensure => present,

. . .

startupscript => ‘puppet-enterprise.sh’,

metadata => {

‘pe_role’ => ‘master’, ‘pe_version’ => ‘3.6.1’ }

}

gce_instance { ‘agent-1’:

ensure => present,

. . .

startupscript => ‘puppet-enterprise.sh’,

metadata => {

‘pe_role’ => ‘agent’, ‘pe_version’ => ‘3.6.1’,

‘pe_master’ => ‘pe-master’ }

}

Page 45: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Turtles All The Way Down

Application

Puppet

Cloud

Page 46: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Security 90s Style

Master

Agent

Agent

Page 47: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Autosign# Whether (and how) to autosign certificate requests.

# This setting

# is only relevant on a puppet master acting as a

# certificate authority (CA).

#

# Valid values are true (autosigns all certificate

# requests; not recommended),

# false (disables autosigning certificates), or the

# absolute path to a file.

[master]

autosign = true

Page 48: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Autosign# Whether (and how) to autosign certificate requests.

# This setting

# is only relevant on a puppet master acting as a

# certificate authority (CA).

#

# Valid values are true (autosigns all certificate

# requests; not recommended),

# false (disables autosigning certificates), or the

# absolute path to a file.

[master]

autosign = $confdir/autosign.conf

Page 49: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Autosign# Whether (and how) to autosign certificate requests.

# This setting

# is only relevant on a puppet master acting as a

# certificate authority (CA).

#

# Valid values are true (autosigns all certificate

# requests; not recommended),

# false (disables autosigning certificates), or the

# absolute path to a file.

[master]

autosign = $confdir/my_autosign

trusted_node_data = true

[agent]

csr_attributes = $confdir/csr_attributes.yaml

Page 50: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Autosign

# Produce attributes for the csr based on instance

metadata

MD="http://metadata/computeMetadata/v1/instance"

INSTANCE=$(curl -fs -H "Metadata-Flavor: Google"

$MD/zone)

NAME=$(curl -fs -H "Metadata-Flavor: Google"

$MD/attributes/puppet_instancename)

UUID=$(curl -fs -H "Metadata-Flavor: Google" $MD/id)

cat > $PUPPET_DIR/csr_attributes.yaml <<END

custom_attributes:

Page 51: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Autosign

# Produce attributes for the csr based on instance

metadata

MD="http://metadata/computeMetadata/v1/instance"

INSTANCE=$(curl -fs -H "Metadata-Flavor: Google"

$MD/zone)

NAME=$(curl -fs -H "Metadata-Flavor: Google"

$MD/attributes/puppet_instancename)

UUID=$(curl -fs -H "Metadata-Flavor: Google" $MD/id)

cat > $PUPPET_DIR/csr_attributes.yaml <<END

custom_attributes:

Page 52: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Trust your data

Master Agent

CSR

Certificate

Facts/Certificate

Catalog

Page 53: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Why do this?

• How fast can you change?

• How frequent?

• At what cost?

• What is your level of automation?

Page 54: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

So what became of Herman Hollerith?

Page 55: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code
Page 56: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

So what became of Herman Hollerith?

Page 57: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

So what became of Herman Hollerith?

Page 58: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Questions ?

Page 59: Puppet Camp Seattle 2014: Puppet: Cloud Infrastructure as Code

Puppetize!