Openstack HEAT tutorials: 1. Deploying an instance with haproxy installed and configured for basic HTTP load balancing
This is a an example of HEAT template for deploying an instance with haproxy installed and configured for basic HTTP load balancing.
Below you my see the script which is composed of three sections:
1. Template format section
This template is written AWS CloudFormation (CFN) format. This is typically expressed in JSON format. The template format and version are specified at the top of the template:
“AWSTemplateFormatVersion” : “2010-09-09″
2. Parameters section
Here we declare the input parameters that have to be provided when instantiating the template. In our case, the Input Parameters are the Glance image ID (image used for launching the instances), instance flavor, network ID, keypair and Security group. These are actually all the parameters required when manually launching an instance. Also, as you may see below, it’s possible to provide default values so that you won’t need to provide all the input parameters, each time.
3. Resources section
Next comes the Resources section where we define the templates for the actual resources that will make up a stack deployed from the HEAT template (e.g. compute instances, networks, storage volumes). In this example, we deploy a single instance and we install haproxy with a basic configuration. The bash script, which is nothing more than a guest customization script, is provided inside the “user data” property. There you may insert any script you like and it will be automatically launched, immediately after the instance instance is created and has network connectivity.
[code lang=”bash”] {
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Heat template for creating an instance with haproxy installed and configured for basic HTTP load balancing",
"Parameters": {
"Instance Image Id" : {
"Description" : "Image Id to be used when launching the instance",
"Type" : "String",
"Default" : "8e66f730-bbfe-4864-8e15-e5611f56cdb8"
},
"Instance Flavour" : {
"Description" : "Flavour to be used when launching the instance",
"Type" : "String",
"Default" : "m1.small"
},
"Network ID" : {
"Description" : "ID of Neutron network into which servers get deployed",
"Type" : "String",
"Default" : "d073e257-bbfb-41d9-af26-e78fea76b30f"
},
"KeyPair" : {
"Description" : "Keypair to be used when launching the instance",
"Type" : "String",
"Default" : "mbalas"
},
"SecurityGroup" : {
"Description" : "SecurityGroup to be used when launching the instance",
"Type" : "String",
"Default" : "MBA_securityGroup"
}
},
"Resources" : {
"Haproxy" : {
"Type" : "OS::Nova::Server",
"Properties" : {
"name" : "Haproxy",
"image" : {"Ref" : "Instance Image Id"},
"flavor": {"Ref" : "Instance Flavour"},
"networks": [{"network":{"Ref" : "Network ID"}}],
"key_name": {"Ref" : "KeyPair"},
"security_groups": [{"Ref" : "SecurityGroup"}, "default"],
"user_data_format": "RAW",
"user_data": { "Fn::Join" : ["", [
"#!/bin/bash -vn",
"apt-get -y updaten",
"apt-get -y install haproxyn",
"echo ENABLED=1 > /etc/default/haproxyn",
"cat << EOF >> /etc/haproxy/haproxy.cfgn",
"listen http-servern",
" bind *:80n",
" balance roundrobinn",
" mode httpn",
" option forwardforn",
" option httpchkn",
" option httpclosen",
" option httplogn",
" timeout client 3hn",
" timeout server 3hn",
" server Ubuntu1 10.100.0.164:80 check inter 2000 fall 3n",
" server Ubuntu2 10.100.0.165:80 check inter 2000 fall 3n",
"EOFn",
"service haproxy start"]] }
}
}
}
}
[/code]
How we launch the template and provide the input parameters:
From the Horizon interface, go to Project -> Orchestration -> Stacks -> Press + Launch stack -> Template source: File -> Template URL: provide the location of the script (from your local hard drive) -> Press Next and this screen will be shown to you:
Here you just have to provide a Stack Name and the Input Paramaters (or leave the default values). Finally, press Launch.
Pingback: Openstack HEAT tutorials: Autoscaling
Pingback: Openstack HEAT tutorials: Autoscaling with Ceilometer