KEMBAR78
Build your own clouds with Chef and MCollective | PDF
Build your own clouds
with Chef & MCollective


Jonathan Weiss
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
Scalarium


Amazon EC2 Cluster Management
   Auto-Config
   Self-Healing
   Auto-Scaling
   One-click-deployment




www.scalarium.com




                                3
Cloud Computing




         Cloud Computing


                           4
5
6
What you get

             Open
             Solaris       Oracle                 Suse

                                       Windows
   Linux
                  Ubuntu


                              CentOS             Red
           IBM
                                                 Hat




                 Infrastructure as a Service
What you really want

    Load
   balancer



  App server



   Database

       Fully configured stack of servers, dependencies, firewalls, …
                                     +
                      your own application deployed
Automation is
    needed for

     • Configuration
     • Healing

     • Scaling

     • Deployment




flickr.com/photos/torek/3788181603
Automation Solutions
Reasons to build your own


  In-house capacity



  Governance: Security and regulations



  Flexibility (or lack of…)




                                          11
Ingredients




              12
Components

                  Communication	

   Host
configuration	

                                     Command &
                                      Control
Command & Control


Responsibilities:
   Communication with IaaS API


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


   Repository of projects &configuration


   Controls which hosts do what&when




                                           14
Command & Control


Responsibilities:                          Implementation:
   Communication with IaaS API               Fog & other API implemenations


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


   Repository of projects &configuration      CouchDB


   Controls which hosts do what&when         Async wokers & agents




                                                                           15
Communication


Responsibilities:
   Distribute commands and responses
    in a scalable & fault tolerant way




                                         16
Communication


Responsibilities:                        Implementation:
   Distribute commands and responses       MCollective / ActiveMQ
    in a scalable & fault tolerant way




                                                                      17
Host Configuration


Responsibilities:
   Actually executes commands


   Responds to cluster changes


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




                                                18
Host Configuration


Responsibilities:                               Implementation:
   Actually executes commands                     Chef


   Responds to cluster changes                    MCollective Agents


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




                                                                         19
Host Configuration
Bootstrapping new servers




                            20
Chef


Open Source Provisioning Tool
   Configures your servers
   Cookbooks & recipes
   Ruby DSL




                                21
Chef




       22
Chef Server




              23
Chef Solo




            24
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
Cookbooks

    Cookbooks	


           apache2	


           memcached	


           mysql	



           rails	

                          26
Memcached Cookbook

    Cookbooks	


           memcachd	


                   attributes	


                   recipes	


                   templates	

                                   27
Memcached Cookbook
   memcached	


         attributes	


                  default.rb	

          recipes	


               service.rb	


                  install.rb	


          templates	


                    default	


                            memcached.conf.erb	

                                                    28
Attributes


cookbooks/memcached/attributes/default.rb




Set default values for variables to use in recipes & templates


                                                                 29
Recipes


cookbooks/memcached/recipes/service.rb




Actual instructions to execute


                                         30
Recipes


cookbooks/memcached/recipes/install.rb




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




                                                           32
Chef Solo Run
 Configuration JSON: /etc/chef/solo.json




 Run Chef Solo




                                          33
Available Resources

 Cookbook File   Ifconfig            SCM
 Cron            Link               Script
 Deploy          Log                Service
 Directory       Mdadm              Subversion
 Erlang Call     Mount              Template
 Execute         Package            User
 File            Remote Directory
 Git             Remote File
 Group           Route
 HTTP Request    Ruby Block




                                                 34
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
Deploy Resource




                  36
Communication
Relaying messages to servers




                               37
Marionette Collective



„a framework to build server orchestration
 or parallel job execution systems“




                                             38
MCollective Architecture




                           39
RPC Calls
 Service: chef-run	

 Service: update-cookbooks	



                                                                    Client	

                                                     Discover 
                                                      agents	

 Service: chef-run	

 Service: update-cookbooks	




                                Message Routing	


    Agents
RPC Calls
 Service: chef-run	

 Service: update-cookbooks	



                                                                 Client	



 Service: chef-run	

 Service: update-cookbooks	

                         Call
                                                     agents	



                                Message Routing	


    Agents
MCollective Agent




                    42
Calling an Agent




                   43
Calling an Agent




                   44
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
Filters on the Command Line




                              46
Filters in Code




                  47
MCollective  Chef

Call Chef action on remote agents/machines




                                             48
MCollective  Chef

Agent running Chef




                     49
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
Scalability  Redundancy


ActiveMQ offers different means
   Network of brokers
   Broker clusters
   Master/Slave




                                  51
Command  Control
Controlling the cloud




                        52
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
Server Roles




               54
Command Software




                   55
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
QA
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: info@peritor.com



© Peritor GmbH - Alle Rechte vorbehalten
Idempotent

Bug or feature?




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




                              59
Two Phases of Chef

1) Compile

   Load all attributesrecipes and build list of actions/dependencies

   Compute attribute tree



2) Run                                   Random Ruby Code runs here
   Actually execute the resources




                                                                        60
Two Phases of Chef

 Use only_if and not_if




 Tell Chef to execute your ressource during compile phase




                                                             61

Build your own clouds with Chef and MCollective