53
Chef for Openstack Mohit Sethi [email protected]

Chef for openstack

Embed Size (px)

Citation preview

Page 1: Chef for openstack

Chef for Openstack

Mohit [email protected]

Page 2: Chef for openstack

Whoami?

Mohit Sethi

Developer, Technical Lead

Senior Engineer at HP R&D

You?

• Developers?

• System Administrators?

• Architects?

Page 3: Chef for openstack

Journey so far?

• 2010-11: • CFEngine,

• Puppet

• Chef

• 2011 - Present• Contributed to Chef core,

• Contributed to Knife cloud plugins such as ec2, azure, hp, openstack, rackspace, google, cloudstack, vsphere, vcloud

• Written extensions for automation tools such as Vagrant, vagrant-hp, vagrant-vsphere

Page 4: Chef for openstack

Goal for today

• Configuration Management Framework – Opscode Chef,• Principles,

• Automation Constructs

Page 5: Chef for openstack

What is Chef?

Chef is a systems integration framework, built to bring the benefits of configuration management to you entire infrastructure.

Page 6: Chef for openstack

Wait, What?

Page 7: Chef for openstack

What is Chef?

Chef is a tool that allows you to define the state your servers(local or cloud) should be in and then enforces that state on your servers.

An API for your entire Infrastructure.

A service that exposes data about the state of your infrastructure

Page 8: Chef for openstack

Why should I use Chef?

You have Servers.

You need to configure them.

Page 9: Chef for openstack

Why should I use Chef?

But I’ve my AWESOME bash scripts, which already does most of ‘those’ things,

Page 10: Chef for openstack

Why else?

We are developers, we write multi-tier applications

Page 11: Chef for openstack

Why else?

We like to make things interesting,

Page 12: Chef for openstack

Why else?

Application grows,

Page 13: Chef for openstack

Why else?

Page 14: Chef for openstack

Why else?Meanwhile 6 months later,

• How did I do that?• Who changed that?• Why did I do it what way?

• Then It dies,• I have to rebuild it• Did I forget anything• How did I do it

• And you will be >>

Page 15: Chef for openstack

Why else?

And you will be…

Page 16: Chef for openstack

Why Chef?Provides:

Page 17: Chef for openstack

Architecture(1000’ view)

Page 18: Chef for openstack

Chef Client runs on your servers

Page 19: Chef for openstack

Client talks to a Chef Server

Page 20: Chef for openstack

Clients authenticate with RSA keys

Page 21: Chef for openstack

Knife is used to talk to Chef-Server & initiate convergence of a server.

Page 22: Chef for openstack

Principles

• Idempotent

• Provision Often

• Infrastructure As Code

• Data-Driven

• Thick Clients, Thin Server

Page 23: Chef for openstack

#1 Idempotent

#1 Chef rule: Recipes/ Infrastructure code should be Idempotent.

The number of Chef runs should not affect the state of the server. The server should converge on the first run. And unless previously defined state changes, additional runs should not change anything.

Say “what to do” not “how”

Page 24: Chef for openstack

#2 Provision Often

If your recipes are not idempotent refer rule #1.

If they are, you should consider provisioning your servers often. Possibly every 5 minutes. Seriously.

Page 25: Chef for openstack

#3 Infrastructure As Code

Infrastructure should be represented as code,

Server configuration, packages installed, relationships with other servers, should be modeled with code to be automated.

Page 26: Chef for openstack

#4 Data-Driven• Separate of policy & data (implemented using Attributes &

DataBags)

• Infrastructure code should not have sensitive data. Though it can have sane defaults.

• Sensitive data should be remain in a secured store, and should only be shared with authorized clients.

Page 27: Chef for openstack

#5 Thick Clients, Thin Servers

As much as possible much work is done by Chef-Client(Nodes)

Pull not Push. Chef-client runs on each node & will interact with server when it needs to.

Server is designed to distribute data to each node, including cookbooks, recipes, templates, files and so on.

Server also retains a copy of state of node at the conclusion of every chef-client.

Page 28: Chef for openstack

Okay! let’s write some infrastructure code…

Page 29: Chef for openstack

Vocabulary

• Nodes == Servers

• Attributes ≈ Variables

• Roles can define a Node’s attributes and what Recipes are applied to that Node

• Clients == Anything that uses the API

• Resources are the basic building blocks to define state

• Related Resources are grouped into Recipes

• Related Recipes are grouped into Cookbooks

Page 30: Chef for openstack

Do I need to know Ruby?

A little

It’s a simple syntax

Page 31: Chef for openstack

Chef-solo

Chef can also run stand-alone

Page 32: Chef for openstack

Nodes == Servers

Nodes have Attributes

Attributes == Variables

Attributes are Searchable

$ knife search node ‘platform:centos’

search(:node, ‘platform:centos’)

Page 33: Chef for openstack

Attributes

Attributes == Variables

Attributes are Searchable

$ knife search node ‘platform:centos’

search(:node, ‘platform:centos’)

Page 34: Chef for openstack

Nodes have RunList

A RunList defines:

What Roles or Recipes to apply in Order.

$ knife node show ks.ms.openstack.com –r {

“run_list”: [

“role[os-base]”,

“role[os-identity]”,

]

}

Page 35: Chef for openstack

Nodes have Roles

Role: What describes a node• webserver

• dbserver

• glance-server

• keystone-server

• …etc

Roles have RunList

Page 36: Chef for openstack

Roles

• Roles have Run-List

Page 37: Chef for openstack

Roles

• Can have other roles!

Page 38: Chef for openstack

Roles

• Can override default attributes

Page 39: Chef for openstack

Roles

• Roles are Searchable

• To find all roles where attribute: max_children takes value 50.

$ knife search role ‘max_children:50’

search(:role, ‘max_children:50’)

Page 40: Chef for openstack

Chef manages Resources on Nodes

• Resource: Declare a description of the state a part of node should be in.

• Have a type

• Have a name

• Have parameters

• Take action to put the resource in the declared state

• Can send notification to otherresources.

Page 41: Chef for openstack

Providers

• Resource take action through providers.

• Know how to actually perform the actions specified by a resource,

• Multiple providers per resources type

• Eg. Resource “package” have providers apt, yum, rubygems, portage, macports, FreeBSD ports, etc

Page 42: Chef for openstack

Resources

Platform

Provider

Page 43: Chef for openstack

Recipes

• Recipes are list of Resources

• Apply resources in the order they are specified

• Recipes are `import` other recipes,

Page 44: Chef for openstack

Recipes are just Ruby!

Page 45: Chef for openstack

Cookbooks

• Cookbooks are packages for recipes,

• Distributable

• Versioned controlled.

• Can have dependency over other Cookbooks

Page 46: Chef for openstack

Cookbook Structure

• Attributes

• Assets(Files/Templates)

• Providers

• Resources

• Recipes

• Metadata

Page 47: Chef for openstack

Cookbook Metadata• Declares:

• Platform support

• Dependencies

• Recipes

Page 48: Chef for openstack

DataBags

• A data bag is a global variable that is stored as JSON data and is accessible from a server.

• Create a data bag using knife

$ knife data bag create DATA_BAG_NAME (DATA_BAG_ITEM)

users = Chef::DataBag.new

• Can be encrypted

• Data values can be fetched from Recipes

Page 49: Chef for openstack

Community Cookbooks

• 1000+ cookbooks for everything- databases, applications, CMS, package management, Hadoop,Cloud deployments

• http://community.opscode.com

• https://launchpad.net/openstack-chef

Page 50: Chef for openstack

Platform Support

• Debian

• Ubuntu

• RHEL

• Centos

• OS X

• Windows

• FreeBSD

• SUSE Enterprise

• Solaris

• SUSE

• IBM AIX

Page 51: Chef for openstack

Chef Flavors

• Opscode Hosted-Chef • http://manage.opscode.com

• Hosted SaaS version of Chef.

• Opscode Enterprise/Private Chef • Private deployments of Opscode Chef Server

• On-Premise deployments

• Open Source Chef• Installation

Page 52: Chef for openstack

Cloud support

• Cloud support by Knife• EC2, Rackspace, HP, Google, Azure, CloudStack, OpenStack, vSphere, vCloud, Joyent, etc

• Extensible • Implement own Resources & Providers,

Page 53: Chef for openstack

Questions??

self.intro do |mohit|

mohit.twitter = @mohitsethi, @openstackindia

mohit.email = [email protected]

end