Openstack HEAT tutorials: 2. Creating multiple resources of the same type using autoscaling group
This example will show you how to create multiple resources of the same type using autoscaling groups.
The real power of autoscaling groups is to use them together with scale-up/down policies in order for Openstack to automatically create new instances (scale-up) or delete instances (scale-down) based on a chosen metric. For example, when the average CPU utilization grows above 50% it will create a new instance (identical to the others) and when the average CPU utilization drops below 15% it will delete one or more instances in order to efficiently use the virtual resources. This complex example, will be detailed in the next tutorial (Tutorial 3).
The example below, uses the autoscaling group to create N identical resources, in this case 10 identical servers.
For details aboout the template section and the parameters section, please look at Tutorial 1
[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" : {
"ApacheServer" : {
"Type": "OS::Heat::AutoScalingGroup",
"Properties" : {
"desired_capacity": 10,
"max_size": 10,
"min_size": 10,
"resource": {
"type" : "OS::Nova::Server",
"properties" : {
"name" : "Apache",
"image" : {"Ref" : "Instance Image Id"},
"flavor": {"Ref" : "Instance Flavour"},
"networks": [{"network":{"Ref" : "Network ID"}}],
"key_name": {"Ref" : "KeyPair"},
"security_groups": [{"Ref" : "SecurityGroup"}, "default"] }
}
}
}
}
}
[/code]