chefconf 2014 - aws opsworks under the hood

45
© 2014 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified, or distributed in whole or in part without the express consent of Amazon.com, Inc. AWS OpsWorks Under the Hood Jonathan Weiss @jweiss Amazon Web Services

Upload: jonathan-weiss

Post on 08-May-2015

2.048 views

Category:

Technology


1 download

DESCRIPTION

AWS OpsWorks under the hood - presented at ChefConf 2014

TRANSCRIPT

Page 1: ChefConf 2014 - AWS OpsWorks Under The Hood

© 2014 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified, or distributed in whole or in part without the express consent of Amazon.com, Inc.

AWS OpsWorks Under the Hood

Jonathan Weiss @jweiss Amazon Web Services

Page 2: ChefConf 2014 - AWS OpsWorks Under The Hood

“Integrated application management service on EC2 – powered by Chef”

Page 3: ChefConf 2014 - AWS OpsWorks Under The Hood

Chef Setup

Chef Client/Zero &

OpsWorks Backend

Chef Client &

Chef Server

Page 4: ChefConf 2014 - AWS OpsWorks Under The Hood

OpsWorks Architecture

OpsWorks Backend

OpsWorks Agent

EC2, EBS, EIP, VPC, ELB, … Auto-Scaling, Auto-Healing,…

On-instance execution via Chef client/zero

Command JSON

Command Log+Status

Page 5: ChefConf 2014 - AWS OpsWorks Under The Hood

Chef Setup in OpsWorks

•  Supported Chef versions: 0.9, 11.4 or 11.10 •  Built-in convenience cookbooks / bring your own •  Chef run is triggered by life cycle event firing •  Event comes with stack state JSON

Page 6: ChefConf 2014 - AWS OpsWorks Under The Hood

Stacks & Layers

Page 7: ChefConf 2014 - AWS OpsWorks Under The Hood

Modeling in OpsWorks

Page 8: ChefConf 2014 - AWS OpsWorks Under The Hood

Layers Group of instances with common behavior & settings

–  Recipes / run_list –  Settings / attributes –  Similar to Chef role

Page 9: ChefConf 2014 - AWS OpsWorks Under The Hood

Built-in Layers

Open Source at http://github.com/aws/opsworks-cookbooks

Rails MySQL PHP HAProxy Node.js Memcached Java Ganglia

Page 10: ChefConf 2014 - AWS OpsWorks Under The Hood

Custom Layers Define your own layers and their run_list

–  Erlang app server –  Cassandra DB cluster –  C daemon –  Custom PHP install –  …

Page 11: ChefConf 2014 - AWS OpsWorks Under The Hood

Custom Layers

Page 12: ChefConf 2014 - AWS OpsWorks Under The Hood

Custom Layers

Page 13: ChefConf 2014 - AWS OpsWorks Under The Hood

Custom Layers

Page 14: ChefConf 2014 - AWS OpsWorks Under The Hood

Event Life Cycle

Page 15: ChefConf 2014 - AWS OpsWorks Under The Hood

Events

Events are triggered when your stack changes: •  Give you fine-grained control •  Faster to execute •  Context: run_list per event per layer (aka role)

Page 16: ChefConf 2014 - AWS OpsWorks Under The Hood

Life Cycle Events

16

setup configure deploy undeploy shutdown

Page 17: ChefConf 2014 - AWS OpsWorks Under The Hood

Instance Life Cycle

new

Page 18: ChefConf 2014 - AWS OpsWorks Under The Hood

Instance Life Cycle

new

Page 19: ChefConf 2014 - AWS OpsWorks Under The Hood

Instance Life Cycle

new

onlin

e

setup

configure

Page 20: ChefConf 2014 - AWS OpsWorks Under The Hood

Instance Life Cycle

new

onlin

e

setup

configure

deploy

Page 21: ChefConf 2014 - AWS OpsWorks Under The Hood

Instance Life Cycle

new

/ st

oppe

d

onlin

e

setup

configure

terminating shutting down

deploy

configure

Page 22: ChefConf 2014 - AWS OpsWorks Under The Hood

Setup Event

•  Sent when instance boots •  Includes deploy event •  Use for initial installation

of software & services

Page 23: ChefConf 2014 - AWS OpsWorks Under The Hood

Setup Event – Recipe Execution Order

AWS OpsWorks

setup recipes Your setup

recipes AWS

OpsWorks deploy recipes

Your deploy recipes

Page 24: ChefConf 2014 - AWS OpsWorks Under The Hood

Configure Event

•  Sent to all instances when any instance enters or leaves online state

•  Use for making sure the configuration is up-to-date

Page 25: ChefConf 2014 - AWS OpsWorks Under The Hood

Deploy Event

•  Sent you deploy via UI/API also part of each setup

•  Use for custom deployment

Page 26: ChefConf 2014 - AWS OpsWorks Under The Hood

Undeploy Event •  Sent via UI/API when

apps are deleted •  Use to remove apps from

running instances

Page 27: ChefConf 2014 - AWS OpsWorks Under The Hood

Shutdown Event

•  Sent when an instance is shut down

•  ~45s to execute •  Use for clean shutdown

Page 28: ChefConf 2014 - AWS OpsWorks Under The Hood

Stack State JSON Each event gets JSON / attributes that define the current stack state:

node[:opsworks]

node[:opsworks][:layers]

node[:opsworks][:instance]

node[:opsworks][:stack]

Page 29: ChefConf 2014 - AWS OpsWorks Under The Hood

Chef Integration

Page 30: ChefConf 2014 - AWS OpsWorks Under The Hood

Search

Stack state JSON available through search search(:node, “name:web1”)

search(:node, “name:web*”)

Attributes generated on nodes are not available

Page 31: ChefConf 2014 - AWS OpsWorks Under The Hood

Search

appserver = search(:node, "role:php-app").first

Chef::Log.info(”Private IP: #{appserver[:private_ip]}")

Exposes: hostname/fqdn, IP/DNS, private IP/DNS, instance type, AMI ID, AZ, …

Page 32: ChefConf 2014 - AWS OpsWorks Under The Hood

Roles

OpsWorks layers mapped as roles search(:node, “role:rails-app”)

search(:node, “role:custom-foo”)

Complete role functionality depends on supporting a “full” chef repo

Page 33: ChefConf 2014 - AWS OpsWorks Under The Hood

Data Bags Define in custom JSON

{ "opsworks": { "data_bags": { "bag_name1": { "item_name1: { "key1" : “value1”, "key2" : “value2”, ... } }, "bag_name2": { "item_name1": { "key1" : “value1”, "key2" : “value2”, ... } }, ... } } }

Page 34: ChefConf 2014 - AWS OpsWorks Under The Hood

{ "opsworks": { "data_bags": { "myapp": { "mysql": { "username": "default-user", "password": "default-pass" } } } } }

mything = data_bag_item("myapp", "mysql") Chef::Log.info("username: #{mything['username']}")

Recipe

Custom JSON

Page 35: ChefConf 2014 - AWS OpsWorks Under The Hood

Encrypted Data Bags

Not supported – Alternative handling: •  Upload encrypted JSON to S3 •  Have instances access via IAM roles in a recipe

Page 36: ChefConf 2014 - AWS OpsWorks Under The Hood

Store Secrets on Amazon S3

Access from instance via IAM instance profiles bucket = node['acme']['bucket'] key = node['acme']['key'] s3 = AWS::S3.new obj = s3.buckets[bucket].objects[key] obj.read

Page 37: ChefConf 2014 - AWS OpsWorks Under The Hood

Berkshelf Integration

Enable Berkshelf in stack settings Supports any version, ships pre-compiled for some

Page 38: ChefConf 2014 - AWS OpsWorks Under The Hood

Berkshelf Integration

Cookbook directories /opt/aws/opsworks/current/cookbooks

/opt/aws/opsworks/current/site-cookbooks

/opt/aws/opsworks/current/berkshelf-cookbooks

Page 39: ChefConf 2014 - AWS OpsWorks Under The Hood

Berksfile

cookbook 'apt'

cookbook 'bluepill', '>= 2.3.1'

cookbook 'ark', git: 'git://github.com/opscode-cookbooks/ark.git'

cookbook 'build-essential', '>= 1.4.2', \

git: 'git://github.com/opscode-cookbooks/build-essential.git', \

tag: 'v1.4.2'

Page 40: ChefConf 2014 - AWS OpsWorks Under The Hood

Environments

•  OpsWorks only supports the implicit _default env •  We are looking into adding proper env support

Page 41: ChefConf 2014 - AWS OpsWorks Under The Hood

Recap

Page 42: ChefConf 2014 - AWS OpsWorks Under The Hood

Main Differences To Chef Server

•  One run vs. discrete events •  Push vs. pull •  Discovery: search & AWS OpsWorks attribute tree •  Encrypted data bags •  Environments & roles

Page 43: ChefConf 2014 - AWS OpsWorks Under The Hood

AWS OpsWorks

•  Life cycle framework •  Highly customizable –

in the end everything is a Chef run •  Expect us to integrate more over time

Page 44: ChefConf 2014 - AWS OpsWorks Under The Hood

More information about AWS OpsWorks

•  Follow us on twitter @AWSOpsWorks •  Find us on YouTube •  Docs: http://aws.amazon.com/documentation/opsworks •  Blog: http://blogs.aws.amazon.com/application-management

Page 45: ChefConf 2014 - AWS OpsWorks Under The Hood

Thank You@jweiss aws.amazon.com/opsworks