61
Build your own clouds with Chef & MCollective Jonathan Weiss

Build your own clouds with Chef and MCollective

Embed Size (px)

DESCRIPTION

One important part of the DevOps movement is infrastructure automation, especially if you are running your application on top of services like Amazon EC2.Everybody's dream is to be able to bootstrap and deploy hundreds or even thousands of machines with a few simple commands. This talk will tell you how you can do this using Open Source tools like Chef and mcollective. Chef manages your servers configuration using a nice Ruby DSL while mcollective orchestrates and commands all your nodes.

Citation preview

Page 1: Build your own clouds with Chef and MCollective

Build your own clouds with Chef & MCollective

Jonathan Weiss

Page 2: Build your own clouds with Chef and MCollective

Who am I?

Working for Peritor in Berlin, Germany

Written, maintain, or involved in

  Webistrano

  Capistrano

  SimplyStored

  Happening

  The great fire of London

http://github.com/jweiss

@jweiss

2

Page 3: Build your own clouds with Chef and MCollective

Scalarium

Amazon EC2 Cluster Management

  Auto-Config

  Self-Healing

  Auto-Scaling

  One-click-deployment

www.scalarium.com

3

Page 4: Build your own clouds with Chef and MCollective

Cloud Computing

4

Cloud Computing

Page 5: Build your own clouds with Chef and MCollective

5

Page 6: Build your own clouds with Chef and MCollective

6

Page 7: Build your own clouds with Chef and MCollective

What you get

Ubuntu Linux

IBM

Oracle

Red Hat

CentOS

Open Solaris Suse

Windows

Infrastructure as a Service

Page 8: Build your own clouds with Chef and MCollective

What you really want

Load balancer

App server

Database

Fully configured stack of servers, dependencies, firewalls, … +

your own application deployed

Page 9: Build your own clouds with Chef and MCollective

Automation is needed for

• Configuration

• Healing

• Scaling

• Deployment

flickr.com/photos/torek/3788181603

Page 10: Build your own clouds with Chef and MCollective

Automation Solutions

Page 11: Build your own clouds with Chef and MCollective

Reasons to build your own

  In-house capacity

 Governance: Security and regulations

  Flexibility (or lack of…)

11

Page 12: Build your own clouds with Chef and MCollective

12

Ingredients

Page 13: Build your own clouds with Chef and MCollective

Components

Host configuration

Command & Control

Communication

Page 14: Build your own clouds with Chef and MCollective

Command & Control

14

Responsibilities:

  Communication with IaaS API

  User Interface (Web, CLI, API): Query, deploy, start, stop

  Repository of projects &configuration

  Controls which hosts do what&when

Page 15: Build your own clouds with Chef and MCollective

Command & Control

Implementation:

  Fog & other API implemenations

  Rails

  CouchDB

  Async wokers & agents

15

Responsibilities:

  Communication with IaaS API

  User Interface (Web, CLI, API): Query, deploy, start, stop

  Repository of projects &configuration

  Controls which hosts do what&when

Page 16: Build your own clouds with Chef and MCollective

Communication

16

Responsibilities:

  Distribute commands and responses in a scalable & fault tolerant way

Page 17: Build your own clouds with Chef and MCollective

Communication

Implementation:

  MCollective / ActiveMQ

17

Responsibilities:

  Distribute commands and responses in a scalable & fault tolerant way

Page 18: Build your own clouds with Chef and MCollective

Host Configuration

18

Responsibilities:

  Actually executes commands

  Responds to cluster changes

  Ensures local host is configured according to commands: Install software, start/stop services, ...

Page 19: Build your own clouds with Chef and MCollective

Host Configuration

Implementation:

  Chef

  MCollective Agents

19

Responsibilities:

  Actually executes commands

  Responds to cluster changes

  Ensures local host is configured according to commands: Install software, start/stop services, ...

Page 20: Build your own clouds with Chef and MCollective

20

Host Configuration Bootstrapping new servers

Page 21: Build your own clouds with Chef and MCollective

Chef

Open Source Provisioning Tool

  Configures your servers

  Cookbooks & recipes

  Ruby DSL

21

Page 22: Build your own clouds with Chef and MCollective

Chef

22

Page 23: Build your own clouds with Chef and MCollective

Chef Server

23

Page 24: Build your own clouds with Chef and MCollective

Chef Solo

24

Page 25: Build your own clouds with Chef and MCollective

Chef-Solo vs. Chef-Server

Chef-Server   Complex

  No concept of different environments, e.g. staging vs. production

  Didn‘t want to run one Chef server per project (and env)

  No lifecycle events, e.g. deployment vs. bootstrap

  Pull vs. push

Chef-Solo

  MCollective agents to push cookbooks and Chef runs

25

Page 26: Build your own clouds with Chef and MCollective

Cookbooks

26

Cookbooks

apache2

memcached

mysql

rails

Page 27: Build your own clouds with Chef and MCollective

Memcached Cookbook

27

Cookbooks

memcachd

attributes

recipes

templates

Page 28: Build your own clouds with Chef and MCollective

Memcached Cookbook

28

memcached

attributes

default.rb

recipes

service.rb

install.rb

templates

default

memcached.conf.erb

Page 29: Build your own clouds with Chef and MCollective

Attributes

29

cookbooks/memcached/attributes/default.rb

Set default values for variables to use in recipes & templates

Page 30: Build your own clouds with Chef and MCollective

Recipes

30

cookbooks/memcached/recipes/service.rb

Actual instructions to execute

Page 31: Build your own clouds with Chef and MCollective

Recipes

31

cookbooks/memcached/recipes/install.rb

Page 32: Build your own clouds with Chef and MCollective

Templates

32

cookbooks/memcached/templates/default/memcached.conf.erb

Page 33: Build your own clouds with Chef and MCollective

Chef Solo Run

33

Configuration JSON: /etc/chef/solo.json

Run Chef Solo

Page 34: Build your own clouds with Chef and MCollective

Available Resources

34

Cookbook File

Cron

Deploy

Directory

Erlang Call

Execute

File

Git

Group

HTTP Request

Ifconfig

Link

Log

Mdadm

Mount

Package

Remote Directory

Remote File

Route

Ruby Block

SCM

Script

Service

Subversion

Template

User

Page 35: Build your own clouds with Chef and MCollective

Deployment with Chef

Deploy resource   Compatible with Capistrano layout

  Supports Capistrano hooks via deploy/hook_name.rb

  Handles source checkout & callbacks

Call custom script

  Arbitrary options, e.g:

Download WAR file

Compile Source

  Automatically wrapped in Chef error handling & notifications

35

Page 36: Build your own clouds with Chef and MCollective

Deploy Resource

36

Page 37: Build your own clouds with Chef and MCollective

37

Communication Relaying messages to servers

Page 38: Build your own clouds with Chef and MCollective

Marionette Collective

„a framework to build server orchestration

or parallel job execution systems“

38

Page 39: Build your own clouds with Chef and MCollective

MCollective Architecture

39

Page 40: Build your own clouds with Chef and MCollective

RPC Calls

Client

Service: chef-run Service: update-cookbooks

Service: chef-run Service: update-cookbooks

Agents

Message Routing

Discover ���agents

Page 41: Build your own clouds with Chef and MCollective

RPC Calls

Client

Service: chef-run Service: update-cookbooks

Service: chef-run Service: update-cookbooks

Agents

Message Routing

Call ���agents

Page 42: Build your own clouds with Chef and MCollective

MCollective Agent

42

Page 43: Build your own clouds with Chef and MCollective

Calling an Agent

43

Page 44: Build your own clouds with Chef and MCollective

Calling an Agent

44

Page 45: Build your own clouds with Chef and MCollective

Filters & Facts

Limit responding agents by filters of facts/classes:

Classes

  Arbitary used defined settings role

  Can be set by userdata

Facts

  Information about local machine

  Plugins for Chef/Ohai, Puppet/Facter

  Examples: Linux version, installed packages, ....

45

Page 46: Build your own clouds with Chef and MCollective

Filters on the Command Line

46

Page 47: Build your own clouds with Chef and MCollective

Filters in Code

47

Page 48: Build your own clouds with Chef and MCollective

MCollective & Chef

Call Chef action on remote agents/machines

48

Page 49: Build your own clouds with Chef and MCollective

MCollective & Chef

Agent running Chef

49

Page 50: Build your own clouds with Chef and MCollective

Security

Clients   Stomp / ActiveMQ user

  AES+RSA plugins: encrypt & sign every message

  SSL plugin: sign every message

  TLS for connection encryption

Middleware

  Topic permissions and subclusters

Agents

  All client security measures available

  RPC authorization and auditing

50

Page 51: Build your own clouds with Chef and MCollective

Scalability & Redundancy

ActiveMQ offers different means

  Network of brokers

  Broker clusters

  Master/Slave

51

Page 52: Build your own clouds with Chef and MCollective

52

Command & Control Controlling the cloud

Page 53: Build your own clouds with Chef and MCollective

Command Software

General capabilities   Stores cluster model

  Interacts with IaaS API (EC2, VMWare & friends)

  Handles recovery & presence

  Integrates communication solution

  Generates host configuration / Chef events

Custom requirements

  User management & authorization

  Business rules & processes

  Deployment recipes & scripts

53

Page 54: Build your own clouds with Chef and MCollective

Server Roles

54

Page 55: Build your own clouds with Chef and MCollective

Command Software

55

Page 56: Build your own clouds with Chef and MCollective

Experiences

Chef   Flexible and powerful

  Easy to learn first steps - easy to write spaghetti recipes

  Some annoyances: pseudo idempotent and 2 phases

  “Write once, test everywhere”

MCollective

  Simple and robust

  Missing presences and events (Nanite has them but has different problems)

  Integrated with Puppet in the future?

56

Page 57: Build your own clouds with Chef and MCollective

© Peritor GmbH - Alle Rechte vorbehalten

Peritor GmbH Blücherstr. 22, Hof III Aufgang 6 10961 Berlin

Tel.: +49 (0)30 69 20 09 84 0 Fax: +49 (0)30 69 20 09 84 9

Internet: www.peritor.com E-Mail: [email protected]

Q&A

Page 58: Build your own clouds with Chef and MCollective

Idempotent

Bug or feature?

58

Page 59: Build your own clouds with Chef and MCollective

59

Will never happen, even if /data/logs/redhat will be created!

Page 60: Build your own clouds with Chef and MCollective

Two Phases of Chef

1) Compile

Load all attributes&recipes and build list of actions/dependencies

Compute attribute tree

2) Run

Actually execute the resources

60

Random Ruby Code runs here

Page 61: Build your own clouds with Chef and MCollective

Two Phases of Chef

 Use only_if and not_if

 Tell Chef to execute your ressource during compile phase

61