shell's kitchen: infrastructure as code (webexpo 2012)

21
Shell’s Kitchen Ano, Chefe! Karel Mina ř ík & Vojt ě ch H ýž a

Upload: karel-minarik

Post on 10-May-2015

3.953 views

Category:

Technology


0 download

DESCRIPTION

Slides for the tutorial by Karel Minarik and Vojtech Hyza at the Webexpo 2012 conference. Please see the GitHub repositories for the code: * http://git.io/chef-solo-hello-world * http://git.io/chef-hello-cloud

TRANSCRIPT

Page 1: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

Shell’s KitchenAno, Chefe!

Karel Minařík & Vojtěch Hýža

Page 2: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

Shell’s Kitchen

Karel Minaříkelasticsearch

@karmiq

Vojtěch HýžaSocial Insider@vhyza

Page 3: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

2 separate deployments

2 dev|ops

> 20 servers in EC2

Page 4: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

Shell’s Kitchen

Karel Minaříkelasticsearch.com

@karmiq

Vojtěch HýžaSocial Insider@vhyza

We’re hiring! We’re hiring!

Page 6: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

Shell’s Kitchen

1

2

3

README

“Hello World”

“Hello Cloud”

15 mins

15 mins

30 mins

Page 7: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

Shell’s Kitchen

“Enable the reconstruction of the business from nothing but a source code repository, an application data backup, and bare metal resources”

— Jesse Robins, Opscode

Page 8: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

“SSH and a for loop is not a solution”

Luke Kanies, inventor of Puppet

for se

rver i

n 174.

129.18

3.197

23.22.

134.13

0

ssh

$user@

$serve

r "sud

o su -

root

-c'

yu

m upda

te --y

es

se

rvice

nginx

restar

t

to

uch /u

sr/loc

al/var

/appli

cation

s/myap

p/tmp/

restar

t.txt

Page 9: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

Shell’s Kitchen

Infrastructure As Code

AutomationRepeatabilityAgilityScalabilityDisaster Recovery

Stephen Nelson-Smith, Test-Driven Infrastructure with Chef, p. 3-4

Page 10: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

# Install Nginx from package#package "nginx"

# Create user and group for Nginx#user node[:nginx][:user] do comment "Nginx User" system true shell "/bin/false"end

group node[:nginx][:user] do members ['ec2-user', node[:nginx][:user]]end

# Create service for Nginx (/sbin/service nginx)#service "nginx" do supports :status => true, :restart => true, :reload => true action [ :enable, :start ]end

# Create log directory#directory node[:nginx][:log_dir] do mode 0755 owner 'root' recursive trueend

# Create Nginx main configuration file#template "nginx.conf" do path "#{node[:nginx][:dir]}/nginx.conf" source "nginx.conf.erb" owner 'root' mode 0644 notifies :restart, resources(:service => "nginx"), :immediatelyend

# Create applications directory#directory "#{node[:nginx][:dir]}/conf/apps" do owner node[:nginx][:user] and group node[:nginx][:user] and mode 0755 action :create recursive trueend

monitrc("nginx") if node.recipes.include?('monit')

add  .

Page 11: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

What is Chef?

An open-source framework, tool and API for infrastructure provisioning and management, maintained and supported by Opscode.

You can use it to maintain a single server for your Wordpress blog, or a cluster of machines in production with equal ease.

You can re-use knowledge and code from the larger #devops community and use the tooling provided by surrounding ecosystem.

Page 12: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

Shell’s Kitchen

Chef Concepts

Recipes

Cookbooks contains resources & providers

{version:  "1"}

Attributes

Templates, Data Bags, Static files, Libraries, ...

Nodes

database-­‐1

directory "/tmp/something" do owner "root" group "root" mode "0755" action :createend

database

RolesServers

Page 13: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

Shell’s Kitchen

Demo 1: “Hello World” with Chef Solo

http://git.io/chef-solo-hello-world

1. Install Nginx

2. Add a simple website for Nginx

3. Use node attributes in the template

4. Launch the node in Amazon EC2

Page 15: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

Shell’s Kitchen

Chef Server

Cookbooks

Nodes

database-­‐1

Servers

Workstation

CookbooksRolesNodesData bagsFull Text Search…

ChefServer

$  knife  ssh  name:data*  "…"

$  knife  status$  knife  search  node  …$  knife  cookbook  upload  …

$  chef-­‐client

Page 17: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

Shell’s Kitchen

Load Balancer

Application 1 Application 1 Application 1

DatabaseRedis | PostgreSQL

elasticsearch A

elasticsearch B

Page 19: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

Shell’s Kitchen

Demo 2: “Hello Cloud” with Chef Server

http://git.io/chef-hello-cloud

‣ Deploy a Ruby On Rails application on EC2 from a “zero state”

‣ 1 load balancer (HAproxy), 3 application servers (Thin+Nginx)

‣ 1 database node (PostgreSQL, Redis)

‣ 2 elasticsearch nodes

‣ Install Ruby 1.9.3 via RVM

‣ Clone the application from (forked) GitHub repository

‣ init.d scripts and full configuration for every component

‣ Restore data from backup (database and search index)

‣ Monitor every part of the stack

‣ Under 30 minutes

Page 20: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

ResourcesINFRASTRUCTURE AS CODE, DEVOPS, CHEF

http://wiki.opscode.com/display/chef/Guides

http://wiki.opscode.com/display/chef/Resources

http://wiki.opscode.com/display/chef/Chef+Solo

http://wiki.opscode.com/display/chef/Architecture+Introduction

http://agilesysadmin.net/ec2-outage-lessons

http://www.aosabook.org/en/puppet.html

http://devopsanywhere.blogspot.it/2011/10/puppet-vs-chef-fight.html

http://www.opinionatedprogrammer.com/2011/06/chef-solo-tutorial-managing-a-single-server-with-chef/

http://blog.nistu.de/2012/03/04/reusability-in-configuration-management-systems/

http://www.slideshare.net/infochimps/chefconf-2012-13016159/23

http://vagrantup.com/v1/docs/provisioners.html

Page 21: Shell's Kitchen: Infrastructure As Code (Webexpo 2012)

Thanks!d