CloudStack Autoscaling I CloudStack Feature Deep Dive


Apache CloudStack 4.18 introduces the Autoscaling feature, enabling users to allocate and release Instances’ resources automatically. This feature streamlines resource management by dynamically adjusting resources to meet demand, thus ensuring optimal performance and cost efficiency .

CloudStack Autoscaling removes any dependency on 3rd party hardware or software solutions. It leverages existing resources, such as the underlying hypervisor and Virtual Router, to gather consumption metrics and, based on user-defined conditions and thresholds, proactively adjust resources to deliver ideal performance and resource consumption.

Feature Overview

The Autoscaling process in CloudStack involves the creation of an Autoscale VM group, which contains a set of Instances that share the same Load Balancing rule. These Instances are automatically scaled up or down based on the evaluation of user-defined policies and conditions.

The Autoscaling feature depends on Apache CloudStack’s Virtual Router (VR) Load Balancing (LB) service. It is therefore only available for Isolated networks and Virtual Private Clouds (VPCs) with the “Load Balancing” service enabled and configured to use the VR.

Figure 1: Add Network Offering form

You can find some prerequisites in CloudStack documentation .

Autoscale VM Group
The Autoscale VM Group’s scaling behaviour is governed by the following components:


Counters represent performance metrics that reveal the state of monitored Instances. CloudStack supports five built-in counters for both Isolated Networks and Virtual Private Clouds (VPCs):
• VM CPU – average percentage
• VM Memory – average percentage
• Public Network – mbps received per Instance
• Public Network – mbps transmit per Instance
• Load Balancer – average connections per Instance

Conditions define the criteria for initiating an autoscaling action, utilizing the counters mentioned earlier. Each condition consists of the following parameters:
• Counter
• Operator. The following five relational operators are supported:
o greater than
o less than
o less than or equal to
o greater than or equal to
o equal to
• Threshold. used in conjunction with the Counter. When the Counter breaches the Threshold value, the Autoscaling initiates either a scale-up or scale-down action, depending on the defined conditions.

Autoscale Policy

An Autoscale Policy defines a set of rules for executing an autoscaling action, by combining various scale-up or scale-down Conditions:
• Conditions. A policy must include at least one condition.
• Duration. The Duration (in seconds) during which the specified conditions must be true to trigger a scale action. The defined conditions should remain true for the entire specified duration for an Autoscaling action to be invoked.
• Quiet Time. This is the cooldown period after initiating an Autoscaling action. The time encompasses the duration required to provision an Instance from its template and the time required for an application to become ready to handle the traffic. This quiet period allows the Autoscale VM Group to achieve a stable state before any further action can occur. The default duration is 300 seconds.
• Action. The scale actions. The options are scale-up and scale-down.

Autoscale VM Profile

The Autoscale VM Profile contains various settings to be used when executing scale-up or scale-down actions. The Autoscale VM Profile includes the following required parameters or settings:

  • Zone. A zone in which the Instances will be deployed.

• Template. A Template consists of a base OS image that may include an application already configured. It is used to provision a new Instance during a scale-up action. When an Instance is deployed from a Template, it can immediately handle traffic from the Load Balancer without any administrator intervention. If an Instance is deployed for a web service, for example, it should have the web server running and any other necessary configurations in place.
• Compute offering. A predefined set of virtual hardware attributes, such as CPU speed, number of CPUs, and RAM size, can be selected by users when creating a new Instance. Select one of the Compute Offerings to be used when provisioning an Instance as part of a scale-up action.

Furthermore, there are some optional settings for Instances that can be taken into consideration:
• Root disk size. the size of the root disk.
• Data disk offering. The offering of an extra disk attached to each Instance in the VM group.
• Data disk size. the size of the data disk.
• Networks. The networks of the Instances. If multiple networks are checked, the related Load Balancing rule Network will be the default one of the Instances.
• SSH key pairs. The SSH Keys of the Instances.
• Affinity groups. The affinity groups of the Instances.
• Userdata. The userdata of the Instances.

The Autoscale VM Group is responsible for associating scale-up and scale-down policies with a Load Balancing rule. It also defines the maximum and minimum number of Instances and the polling interval. When setting up an Autoscale VM Group, you will need to specify a name that will be used as a prefix for the Instances’ names, ensuring clarity and organization.

Here is a summary of the various parameters involved in the Autoscale VM Group:

• Name. The name of the VM group, which will be used as a prefix for new Instances.
• Load Balancing rule. Automatically assigns newly created Instances to the Load Balancing rule and removes expunged Instances from it.
• Scale-up policies. These policies determine when a scale-up action occurs. CloudStack will create an Instance if the number of Instances does not exceed the “Max Instance” limit and all conditions in one of the scale-up policies are met.
• Scale-down policies. These policies determine when a scale-down action occurs. CloudStack will expunge an Instance in the group if the number of Instances is larger than the “Min Instance” limit and all conditions in one of the scale-down policies are met.
• Min Instance. The minimum number of active Instances assigned to a Load Balancing rule, ensuring at least the configured number of active Instances are available to serve traffic.
• Max Instance. The upper limit of active Instances that can be assigned to a Load Balancing rule.

Polling interval. The frequency at which the conditions (a combination of counter, operator, and threshold) are evaluated before taking a scale-up or down action. The default polling interval is 30 seconds.

Supported APIs

To manage and interact with the Autoscaling feature in CloudStack, several APIs are supported. These APIs allow for creating, listing, updating, and deleting various components related to Autoscaling. The table below provides an overview of the supported operations for each API:

Parameter Operation Notes
Counter Create, List, Delete (*) (*) Only ROOT admin only can delete counter
Condition Create, List, Update (*), Delete (*) New API added in CloudStack 4.18.0
Autoscale Policy Create, List, Update, Delete
Autoscale VM profile Create, List, Update, Delete
Autoscale Vm group Create, List, Update, Delete (*) (*) New parameter: cleanup added in CloudStack 4.18.0

By utilizing these APIs, users can effectively manage their Autoscaling configurations within CloudStack using the CloudMonkey command-line tool or integrating any other system using the CloudStack API.

Setup an Autoscale VM group
In this section, we will describe the process of setting up an Autoscale VM Group to provide HTTP services, wherein the application will be installed using a userdata script, using a CentOS 7 Template that has cloud-init pre-configured to work with Apache CloudStack.

Before creating an Autoscale VM Group, there are several actions and configurations that need to be completed.

1. Registering a new Centos 7 Template
Register a new Template with the following settings:

Name CentOS 7
Description CentOS 7
Hypervisor KVM
Format QCOW2
OS type CentOS 7

Instances created from this Template will automatically retrieve the userdata from the CloudStack VR and perform specified actions during start-up.

If you are running another hypervisor (eg. VMWare or XenServer), you can find supported Templates at

2. Creating an Isolated Network and configuring a Load Balancing rule
To configure a Load Balancing rule for use in the Autoscale VM Group, you will first need to create an Isolated Network and acquire a new Public IP address. Load Balancing rule can also be created on an existing Network and Source NAT IP address, which will be shown during the Autoscale VM Group setup process.

With everything in place, you can now create a Load Balancing rule from the “Load Balancing” tab on the details page of the Public IP. Unlike a traditional Load Balancing rule, an additional field called “Autoscale” is presented, which should be set to ‘Yes’ in order for it to be available during the creation of a new Autoscale VM Group.

3. Exposing the HTTP service to the internet
In order to access the HTTP service running on the Instances, it is necessary to open firewall port 80 for the related Public IP from the “Firewall” tab:

It is also important to add egress rules to the Isolated Network to permit outgoing traffic from the Instances, especially since they need to install some packages from the internet. The following rule will allow all outgoing traffic from the Instances:

4. Other resources
If you plan to use related resources in the Autoscale VM Group, it is recommended to create them in advance. These resources may include, but are not limited to:
• Service Offering
• Disk Offering
• SSH Key Pairs
• Affinity Groups
• Additional Networks
Creating an Autoscale VM Group
With all the prerequisites met, navigate to the “Compute” section in the left menu and click on “Autoscale VM Groups”, and then click on the “New Autoscale VM Group” button which will open the wizard:

1. Select a Zone
2. Select a Template
The registered “CentOS 7” Template can be found in the “My templates” tab.

3. Select a Computer Offering
Please note that custom Service Offerings are not supported by the Autoscaling feature and will be filtered out during the selection process.

4. Select a Data disk offering (optional)
If you wish to add an extra Data Volume to the Instances, select the “Data Disk” option to display a list with the available Disk Offerings, and then choose the one that best suits your needs.

5. Select a Network
You must choose at least one network for VMs in the Autoscale VM group. The default network must be an Isolated network or a VPC tier that supports Autoscaling and has Load Balancing rules in place. Additional Networks can be of any type, including Isolated, Shared, or L2 Networks.

6. Select a Load Balancing rule
The Load Balancing rules of the default Network selected in the “Select Network” step are listed. You need to choose one of them for your Autoscale VM Group.

Please note, the Load Balancing rule must not be used by any Instances. If the Load Balancing rule is already being used by an Instance, it cannot be utilized by the Autoscale VM Group.

7. Scale-up policies
An Autoscale VM Group must have at least one scale-up policy. The Autoscale VM Group will be scaled up when all conditions in a scale-up policy are matched. Scale-up policies will be checked before scale-down policies.

You can create multiple scale-up policies by clicking the “Add Policy” button. Conversely, you can click “Remove policy” to remove any policy that is not needed.

Also, multiple conditions in a policy are supported. Please note, a counter can only be used once. For example, if the counter “VM CPU – average percentage” is used, you cannot create another condition with the same counter. However, it can be used in different policies.

8. Scale-down policies
As mentioned previously in the scale-up policy, Autoscale VM Group must have at least one scale-down policy, it is mandatory for both. The Autoscale VM Group will be scaled down when all conditions in a scale-down policy are matched. Scale-down policies will be checked after scale-up policies.

The other rules are the same as Scale-up policies.

9. Advanced mode
Select “Show advanced settings” to display advanced options. You can optionally choose one or more SSH Key Pairs and Affinity Groups.
In the userdata field, use the following shell script:
yum install -y httpd
sed -i -e ‘/Options Indexes FollowSymLinks/s/$/ ExecCGI/’ \
          -e ‘s/DirectoryIndex index.html/DirectoryIndex’ \
          -e ‘s/#AddHandler cgi-script .cgi/AddHandler cgi-script .py/’ /etc/httpd/conf/httpd.conf
cat << EOF > /var/www/html/
#!/usr/bin/env python
import time
import socket
print(‘Content-type: text/html\n\n’)
print(‘<p style=”text-align: center;”>Hello World!!!</p>’)
print(‘<p style=”text-align: center;”><strong> Instance: </strong>{}</p>’.format(socket.gethostname()))
chmod 705 /var/www/html/
systemctl enable httpd.service
systemctl restart httpd.service
When the Instances start, the cloud-init present in the Template will retrieve this userdata and execute the following actions:
• install and configure the httpd package.
• create an python script. It returns the HTTP response after 5 seconds used to simulate concurrent HTTP requests.
• enable and start the httpd service.
10. Details
Enter the name, maximum and minimum members, Expunge VM grace period (in seconds), and Polling interval (in seconds) as shown below. This will be used only for testing purposes and does not refer to a real production environment.
Once everything is set up, click the “Create” button to create the Autoscale VM Group.
The process of “Autoscale” creation will be displayed shortly thereafter.

Testing Autoscaling

Now that the Autoscale Virtual Machine Group has been established, let’s allow some time for the minimum required number of members (Instances) to be deployed.
To view the active Instances, navigate to the Compute section and select the “Autoscale VM Group”:
To access the details of the “Autoscale VM Group”, click on its name and then choose “View Instances.” This will display a comprehensive list of all Instances within the Group:
Two Instances have been created successfully as the minimum member is set to 2.


With ApacheBench , you can simulate concurrent HTTP requests to initiate the scale-up action in the Autoscale VM Group. The command below will send 10 million requests, with 30 concurrent requests targeting the HTTP server we created using the CloudStack Load Balancing rule. (Please note the importance of including the final slash “/” in the URL).

ab -n 10000000 -c 30

After approximately 10 minutes, the Autoscale VM Group has scaled up to 10 Instances, reaching the maximum number of members for the group:

By executing the following SQL query on the CloudStack database, you can view the creation timestamps of the Instances within the Autoscale VM Group:


Cancel the previous command, which will result in the requests dropping to 0 and initiating the scale-down action for the Autoscale VM group. After 10 minutes, the Autoscale VM Group has successfully scaled down to 2 Instances, achieving the minimum member number for the group:

Once more, by executing the following SQL query on the CloudStack database, you can observe the removal timestamps of the Instances within the Autoscale VM Group:

Managing AutoScale VM group
You can manage the Autoscale VM Group using the CloudStack UI, which provides the following options:
• View AutoScale VM Group details
• Disable and Enable AutoScale VM Group
• Update AutoScale VM Group
• Update AutoScale VM profile
• Manage Load Balancing rule
• Manage AutoScale VM policies and conditions
• View Events

View AutoScale VM Group details
You can view the details of the Autoscale VM Group by following these steps:
• Log in to the CloudStack UI as an administrator or end user.
• In the left navigation, choose Compute -> AutoScale VM Groups.
• Select the AutoScale VM Group you wish to work with.

Disable and Enable AutoScale VM Group
When the AutoScale VM group is enabled, click the first icon on the top-right to disable it:

When the AutoScale VM group is disabled, click the first icon on the top-right to enable it:

Update AutoScale VM Group
By clicking the Edit button, you can modify: Name, maximum and minimum members, and the Polling interval variables.
Note: Be sure to disable the Autoscale VM Group beforehand.

Update AutoScale VM profile
To view the VM Profile of the Autoscale VM Group, navigate to the Autoscale VM Profile tab:

To update the VM profile, click the “Edit Autoscale VM Profile” button. (Please ensure that the Autoscale VM Group is disabled beforehand):

Additionally, you can modify the deployment parameters of the Instances:

The following deployment parameters are supported:
• affinitygroupids: The UUIDs of the affinity groups, separated by a single comma character (,).
• diskofferingid: The UUID of the data disk.
• disksize: The size of the data disk. This is valid only if the disk offering is dynamic.
• keypairs: The names of the SSH Key pairs, separated by a single comma character (,).
• networkids: The UUIDs of the VM networks, separated by a single comma character (,).
• overridediskofferingid: The UUID of the override disk offering for the ROOT disk.
• rootdisksize: The size of the ROOT disk. This overrides the size of the VM template.
• securitygroupids: The UUIDs of the security groups, separated by a single comma character (,). This is valid only if the network provider is Netscaler.

Please ensure you input the correct values, as these entries have no validation.

Manage Load Balancing rule
To view the details of the Load Balancing rule, click the “Load Balancing rule” tab:

Click the first icon to edit the rule:

You can configure the stickiness policy by clicking the “Configure” button located under the “Stickiness” column.

Manage AutoScale policies and conditions
To view the scale policies for the Autoscale VM Group, click either the Scale-up Policy or Scale-down Policy tab, and then select the “Edit” button located in the “Action” column to modify the policy:

Click the icons of each condition to edit or remove the condition:

If you wish to create a new condition for the policy, input the Counter and Threshold values, select an operator, and then click the “Add Condition” button:

Clicking the “Add Policy” button allows you to create a new policy with the first condition in the policy:

Clicking the “Remove Policy” button will remove the selected policy.

View Events

To view the related events, navigate to the Events tab. Here, you can view the events pertaining to the Autoscale VM Group:

This may include, but is not limited to:
• Disabling / Enabling / Updating Autoscale VM Group
• Scale-up actions and results
• Scale-down actions and results


Apache CloudStack 4.18’s VM AutoScaling feature enables users to deploy services with automatic VM allocation and resource release. This feature is self-contained and does not depend on third-party software or hardware. It also supports a variety of metrics from underlying hypervisors and CloudStack VR. The feature is seamlessly integrated into CloudStack’s API and UI for easy management and control.



Related Posts:

Download a step-by-step guide to migrate your existing vSphere environment to a robust IaaS cloud environment based on Apache CloudStack and the KVM Hypervisor, ensuring a smooth, low-friction migration journey.