Autoscaling is one of the more interesting (and outstanding) features of OpenStack Heat. In this post, you’ll build a Devstack environment in a VM with Heat, Neutron, and Ceilometer. This will enable you to run the Autoscaling examples.
Getting Started
To get started, copy the following into a Vagrantfile and vagrant-up. This generally takes 3-5 minutes. Now that you have the VM powered on we need to get Devstack running. To do that, run the following commands:
vagrant ssh sudo su stack cd ~/devstack/ ./stack.sh
Note: Now is the time to top off your coffee and batch process your emails. It’s going to be a while. On my box: stack.sh completed in 2679 seconds.
Basic WordPress
Now that Devstack is up and running, let’s dive right into the examples. First we’ll build a single WordPress install just to get a feel for things. To do that, run the following commands:
source ~/devstack/openrc cd ~/heat-templates/hot/ ssh-keygen -t rsa -N "" nova keypair-add --pub-key ~/.ssh/id_rsa.pub testkey heat stack-create WordPress -f F20/WordPress_Native.yaml -P key_name=testkey
What we did, was set some environment variables for our credentials (as who wants to type those out EVERY time?). Next we moved into where we cloned the heat templates, generated an SSH key, and added it to Nova as ‘testkey’. Finally we launched our heat command.
Let’s break that command down some:
- heat – The CLI tool we’re calling stack-create – This follows the noun-verb nomenclature of OpenStack. For heat, the ‘thing’ on which you operate is a stack. In this case we’re instructing heat to create a stack.
- WordPress – This provides the name of the stack. These should be unique within a tenant.
- -f F20/WordPress_Native.yaml – This specifies the template file to use. In this case, the Fedora 20 WordPress install.
- -P key_name=testkey – -P tells the heat client that we are providing parameters that are requested within the template. In this case, key_name is a required parameter. So we tell it to use the testkey we created.
Ok, it should be done building now, let’s use another heat command to check:
heat stack-list +--------------------------------------+------------+-----------------+----------------------+ | id | stack_name | stack_status | creation_time | +--------------------------------------+------------+-----------------+----------------------+ | 5fad5da6-75e9-40b2-a32f-86345b0263f3 | WordPress | CREATE_COMPLETE | 2014-04-04T17:33:08Z | +--------------------------------------+------------+-----------------+----------------------+
There we go! Let’s find out a bit more about it, we do that with heat stack-show:
heat stack-show WordPress +----------------------+---------------------------------------------------------- | Property | Value +----------------------+---------------------------------------------------------- | capabilities | [] | creation_time | 2014-04-04T17:33:08Z | description | Heat WordPress template to support F20, using only Heat | | OpenStack-native resource types, and without the | | requirement for heat-cfntools in the image. WordPress
Note, this can be enough of the name to be unique, or the UUID. In most cases, you’ll want to use the UUID. Finally, let’s clean up our environment to make room for the autoscale example:
heat stack-delete 5fad5da6-75e9-40b2-a32f-86345b0263f3 +--------------------------------------+------------+--------------------+----------------------+ | id | stack_name | stack_status | creation_time | +--------------------------------------+------------+--------------------+----------------------+ | 5fad5da6-75e9-40b2-a32f-86345b0263f3 | WordPress | DELETE_IN_PROGRESS | 2014-04-04T17:33:08Z | +--------------------------------------+------------+--------------------+----------------------+ heat stack-list +----+------------+--------------+---------------+ | id | stack_name | stack_status | creation_time | +----+------------+--------------+---------------+ +----+------------+--------------+---------------+
Autoscaling WordPress with Heat
Sorry for the delay in getting here, however, covering the basics will let us skip a lot of that now. The Autoscale environment is a bit more complex. That is, we have the following:
Load Balancer (LBaaS) –> Web Tier (Autoscaling Group) –> Database Tier
To build the stack, we need to find out some things about our environment. Specifically a subnet ID to place the load balancer and nodes on and an Image ID for the base of our webserver & db servers. Let’s do that:
neutron subnet-list +--------------------------------------+----------------+-------------+--------------------------------------------+ | id | name | cidr | allocation_pools | +--------------------------------------+----------------+-------------+--------------------------------------------+ | 82596713-60ff-42ee-b766-6c501991cf55 | private-subnet | 10.0.0.0/24 | {"start": "10.0.0.2", "end": "10.0.0.254"} | +--------------------------------------+----------------+-------------+--------------------------------------------+ $ glance image-list +--------------------------------------+---------------------------------+-------------+------------------+-----------+--------+ | ID | Name | Disk Format | Container Format | Size | Status | +--------------------------------------+---------------------------------+-------------+------------------+-----------+--------+ | 7b3bf53c-3875-4f7c-bc6d-eff11290078c | F19-i386-cfntools | qcow2 | bare | 469383680 | active | | 134c4d81-5c00-45d5-b089-9fbd2d5b9afc | F19-x86_64-cfntools | qcow2 | bare | 528297984 | active | | 64ade0c6-9e10-4257-9884-7406d68d49de | Fedora-x86_64-20-20131211.1-sda | qcow2 | bare | 214106112 | active | +--------------------------------------+---------------------------------+-------------+------------------+-----------+--------+
Now that we have those, let’s fire up the build:
heat stack-create WP-Autoscale -f autoscaling.yaml -P database_flavor=m1.small -P subnet_id=82596713-60ff-42ee-b766-6c501991cf55 -P key="testkey" -P flavor=m1.small -P image=7b3bf53c-3875-4f7c-bc6d-eff11290078c +--------------------------------------+--------------+--------------------+----------------------+ | id | stack_name | stack_status | creation_time | +--------------------------------------+--------------+--------------------+----------------------+ | f736fd6f-0348-4381-b4e5-7a4da4c3282e | WP-Autoscale | CREATE_IN_PROGRESS | 2014-04-04T17:45:25Z | +--------------------------------------+--------------+--------------------+----------------------+
On my box, this takes A WHILE to complete. Once it’s done, you can use the same commands to view the environment, or, you can log into the dashboard and check it out:
One thought on “Autoscaling with Heat on Devstack”