Code Monkey home page Code Monkey logo

chef-elb's Introduction

Chef Helpers

This cookbook handles configuring Elastic Load Balancers at AWS

Installation

The easiest way to install this is to use knife-github-cookbooks:

gem install knife-github-cookbooks
knife github cookbook install websterclay/chef-elb

Usage

This cookbook is designed to be run on a single node in your infrastructure. I have a role called the 'rooster' I assign to one node to coordinate AWS API calls based on the presence of other nodes.

Put recipe[elb] in the runlist of your coordinating node to install the required dependeicnes on that node. Then, in a recipe also in that node's runlist:

# Load your AWS credentials databag
aws = data_bag_item("aws", "main")

elb_load_balancer "http-frontend" do
  aws_access_key        aws['aws_access_key_id']
  aws_secret_access_key aws['aws_secret_access_key']
  search_query          "role:app"
  action :create
end

This will automatically create a Elastic Load Balancer that listens on port 80 and forwards requests to all servers that match the specified search on port 80. You can change those defaults by specifying the listeners attribute:

elb_load_balancer "http-frontend" do
  aws_access_key        aws['aws_access_key_id']
  aws_secret_access_key aws['aws_secret_access_key']
  search_query          "role:app"
  listeners             [{"InstancePort" => 8080, "Protocol" => "HTTP", "LoadBalancerPort" => 80}]
  action :create
end

You can also specify the region attribute to change what region the ELB is created in, or specify the instances manually if you don't want to use a search:

elb_load_balancer "ap-tcp-frontend" do
  aws_access_key        aws['aws_access_key_id']
  aws_secret_access_key aws['aws_secret_access_key']
  instances             ['i-xxxxx', 'i-xxxxx']
  region                'ap-southeast-1'
  listeners             [{"InstancePort" => 1234, "Protocol" => "TCP", "LoadBalancerPort" => 1234}]
  action :create
end

You can also do SSL, but it's a little funky.

First, you have to upload your cert.

Then setup your listeners array like so:

elb_load_balancer "http-and-https" do
  aws_access_key        aws['aws_access_key_id']
  aws_secret_access_key aws['aws_secret_access_key']
  search_query          "chef_environment:#{node.chef_environment} AND role:my_ssl_app"
  listeners             [
    {
      "InstancePort"     => 80,
      "Protocol"         => "HTTP",
      "LoadBalancerPort" => 80
    },
    {
      "InstancePort"     => 80,
      "Protocol"         => "HTTPS",
      "LoadBalancerPort" => 443,
      "SSLCertificateId" => "arn:aws:iam::xxxxxxxx:server-certificate/YourCertName"
    }
  ]
  action :create
end

This resource can't update the cert ID for you yet because of missing support in Fog - it will only do that on ELB creation, but you should update it to reflect reality.

Caveats

The cookbook automates determining what availability zones your instances are in and automatically registers the instances. ELB's distribute traffic equally between all enabled Availibity Zones. It's up to you to confirm that your instance distribution is equal if you have instances on more than one AZ.

Resources

ELB Docs

Author

Jesse Newland
[email protected]
@jnewland
jnewland on freenode

License

Author:: Jesse Newland (<[email protected]>)
Copyright:: Copyright (c) 2011 Webster Clay, LLC
License:: Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

chef-elb's People

Contributors

jnewland avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

tgroten

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.