The shift to cloud computing means that organizations are undergoing a major shift as they develop scale-out infrastructure that can respond to apace of business change faster than ever before. Opscode Chef® is an open-source systems integration framework build specifically for
automating the cloud by making it easy to deploy and scale servers and applications throughout your infrastructure. Join us for this session
containing an introduction to Chef including:
An Overview of Chef
The Chef Architecture
Cookbook Components
System Integration
Live demo launching a Java Stack on Amazon EC2, Rackspace, Ubuntu, and
CentOS
[Presented as part of the Open Source Build a Cloud program on 2/29/2012 - http://cloudstack.org/about-cloudstack/cloudstack-events.html?categoryid=6]
35. That looks like this extra_packages = case node['platform'] when "ubuntu","debian" %w{ ruby1.8 ruby1.8-dev rdoc1.8 ri1.8 libopenssl-ruby } end extra_packages.each do |pkg| package pkg do action :install end end
36. Or this search(:users, '*:*') do |u| user u['id'] do uid u['uid'] shell u['shell'] home "/home/#{u['id']}" end directory "#{home_dir}/.ssh" do owner u['id'] group u['gid'] mode "0700" end template "#{home_dir}/.ssh/authorized_keys" do source "authorized_keys.erb" owner u['id'] group u['id'] mode "0600" variables :ssh_keys => u['ssh_keys'] end end
37.
38.
39. Upload your infrastructure knife cookbook upload chef-client knife cookbook upload java knife cookbook upload jpackage knife cookbook upload ntp knife cookbook upload sudo knife cookbook upload tomcat knife cookbook upload users knife cookbook upload sample knife role from file base.rb knife role from file tc.rb knife role from file sample.rb knife data bag create users knife data bag from file users mray.json
40. Build it somewhere #EC2 knife ec2 server create -S mray -i ~/.ssh/mray.pem -x ubuntu -G default -I ami-a7a97dce -f m1.small -d omnibus -r 'role[base],role[tc],role[sample] ’ #Rackspace knife rackspace server create --image 110 --flavor 2 -i ~/.ssh/mray.pem -d omnibus -r 'role[base],role[tc],role[sample] ’ #CloudStack knife cs server create -S "small instance" -T "CentOS 5.5(64-bit) no GUI (KVM)" -i ~/.ssh/mray.pem -d omnibus -r 'role[base],role[tc],role[sample] ’ #Ubuntu Linux VM knife bootstrap test.lab -i ~/.ssh/mray.pem -x ubuntu --sudo -d omnibus -r 'role[base],role[tc],role[sample]'
41. Tomcat stack deployed ec2-107-21-179-169.compute-1.amazonaws.com [Thu, 23 Feb 2012 03:16:27 +0000] INFO: Chef Run complete in 125.548799554 seconds ec2-107-21-179-169.compute-1.amazonaws.com [Thu, 23 Feb 2012 03:16:27 +0000] INFO: Running report handlers ec2-107-21-179-169.compute-1.amazonaws.com [Thu, 23 Feb 2012 03:16:27 +0000] INFO: Report handlers complete Instance ID: i-ee18148b Flavor: m1.small Image: ami-0c6ebd65 Region: us-east-1 Availability Zone: us-east-1b Security Groups: default SSH Key: mray Root Device Type: instance-store Public DNS Name: ec2-107-21-179-169.compute-1.amazonaws.com Public IP Address: 107.21.179.169 Private DNS Name: ip-10-120-255-91.ec2.internal Private IP Address: 10.120.255.91 Environment: _default Run List: role[base], role[tc], role[sample]
Contratulations! You have yourself some clooooud. But now what?
But then what? 5 minutes later, you can have an entire rack of servers at your disposal. But until you do one important thing, all they ’re doing is sitting around eating electricity and costing you money.
Introducing Chef. Hopefully you ’ve already met! Today we're going to talk about what Chef is and what it's good for.
APIs are awesome. They ’re what make the Cloud the Cloud. You can provision resources by simply flinging the right combination of packets at the appropriate DNS address.
And Chef can help with that. Knife is our command line tool for talking to APIs And we have plugins for all sorts of cloud providers, both public and private. This lets you provision a server, install the chef agent on it and configure it as a database, webserver, tomcat stack or whatever from a single command.
Let's walk through the evolution of your infrastructure. Things are going well, you've just started a new project and your new application has come online.
As you get your feet under you and get a feel for what you're doing, you move your database to another machine to help handle the overloaded box.
Turns out, the database was the bottleneck, so you add another.
Demand continues to grow, so you add another application server.
You're going to need a load balancer for that of course, so everyone can use the same IP.
And things are really taking off now, 2 load balancers, 5 application servers and a pair of databases. We're growing fast!
Caching, time to add some
This Infrastructure has a Topology. All the nodes are talking to each other and need to know about their individual interests. Maybe you don ’t want to do it that way.
How should I know. It ’s your application. Your application is unique, and so is your infrastructure. They evolve organically.
And as they evolve, things continue to change as you switch out components and scale
And success breeds success, we're going nuts now.
And a basic fact about Infrastructure -- it EVOLVES.
Currently, the most widely used configuration management strategy is Cloning and Snapshotting. THIS DOES NOT WORK (and you know it.)
OK, it's a JBoss stack on PostgreSQL with Nagios monitoring.
Policy change time!!! SSH on port 22 is a security liability (OK, maybe not, but stick with the story)
First we'll update the sshd_config on 6 golden images
We'll have to replace the instances that are there
12 new boxes, be careful not to break anything. We only have 30 minutes
IP addresses all changed, since we're in the cloud right? Oh wait, Bob screwed up.
Tracking all these changes by hand breaks down fast. Mistakes get made and things get overlooked.
Keep track of all the steps required to take bare metal systems to doing their job in the infrastructure. It is all about the policy. Taking all the systems that have been configured to do their job, and make them work together to actually run the infrastructure.
How do we do this? WRT Chef, we talk about Fully Automated Infrastructure. Chef provides a framework for fully automating infrastructure, and has some important design principles. Chef makes it easy to reason about your infrastructure at scale and the predictable ordering makes it easy to understand what ’s going on. The declarative Ruby configuration language is easy to read, easy to share and flexible enough to do powerful things. Chef gives you the tools you need to manage large scale infrastructure in a coherent, logical fashion that can be picked up by the next person doing your job.
In Chef a Node is an Abstraction of a server. With the chef server, node state data is persisted between runs. The edge node does all the heavy lifting. Resources are the things on Nodes that we manage. ... a collection of Resources that can span nodes and networks. Resources are simple things that you deal with every day as a systems administrator or developer. Resources include files, directories, mounts, routes, users, groups, packages installations, source code deployments, configuration files, and “stuff” in general.
All this is arranged in a very specific way, to it acts in concert to provide ...
a service. That ’s it. An Application Infrastructure provides a view of all it’s component nodes and their attributes, as well as information that needs to be shared among resources.
When dealing with Chef, need to literally “think outside the box”, by shifting your thinking about configuration away from a single system, to that of an Application Infrastructure. The concept of an Infrastructure is an abstract one with a specific technical meaning. When we talk about Infrastructure, we mean..
Chef gives you declarative interfaces into the Resources on those Nodes. Being declarative means that you say what you want to do, instead of how to do it. For example, you declare that package foobar-1.2.3 should be installed, or that the directory /var/log/foobar should exist. Chef pulls down policy from the chef-server, ensuring that a node down for maintenance will receive its policy update when it comes back online.
Because we use a 3GL for the recipe config files, we can use features of ruby like case statements and iterative loops. Sysadmins don ’t need to be afraid of Ruby, they’ve been dealing with sub-standard programming languages like configuration files for years. They ’re also not limited to what the language tells them they can do.
By using Ruby we can make calls to web services, in this case we're calling search against the Chef server for all the users stored there. We're going to iterate over them, create the users, their home directories and write out the authorized_keys file. As you need to do more complex and powerful things with your infrastructure, Chef's use of Ruby will allow you to harness whatever resources you need.
The nodes are going to execute their run lists to configure their Resources defined in your Cookbooks and Recipes. The chef-client maintains the state of your machines, and are also responsible for generating the configuration that is the topology of the infrastructure.
This is where the sauce is, and what enables systems integration. (back up to previous slide) When provisioning on Clouds, you typically don ’t get to do up front IP address planning So how do you point a web server to its database? You search for it.
Chef is hackable! Permissive Apache2 license, vibrant community of awesome folks. More than 360 individual contributors, over 70 corporate contributors. Community is very important to us. That's why we're here.