Use Auto Scaling to scale a CLB server group
Auto Scaling integrates with Classic Load Balancer (CLB) to automatically add or remove Elastic Compute Service (ECS) instances from a CLB server group based on real-time resource usage. When a scaling event fires, the changes sync to the server group — CLB routes traffic to healthy instances and stops routing to removed ones.
When complete, your architecture looks like this:
ECS01 is the initial backend server. When CPU utilization reaches 60%, Auto Scaling creates a new ECS instance and adds it to the CLB server group. When CPU utilization drops below 30%, Auto Scaling removes that instance.
Prerequisites
Before you begin, ensure that you have:
A CLB instance in the Running state. See Create and manage CLB instances.
A vServer group on that CLB instance with ECS01 added. In this example, the server group is named RS1. Auto Scaling-created instances are added to this same group, so CLB applies the same forwarding rules to all backend servers.
A custom image created from ECS01. See Create a custom image from an instance. Auto Scaling uses this image to create new instances that are deployment-ready.
Health checks enabled on the CLB instance. See Configure and manage CLB health checks. Health checks ensure CLB only routes traffic to instances that are ready to serve requests.
At least one listener created on the CLB instance. See Add an HTTP listener.
The vServer group, security group, Virtual Private Cloud (VPC), and vSwitch of any Auto Scaling-created instance must match those of ECS01. This lets CLB apply the same forwarding rules and security policies to all instances in the group.
Step 1: Create a scaling group
A scaling group defines the capacity boundaries for your backend servers — the minimum number Auto Scaling maintains and the maximum it can scale to. These boundaries let you control cost while ensuring enough capacity to handle demand.
Log on to the Auto Scaling console.
Log on to the Auto Scaling console.
In the left-side navigation pane, click Scaling Groups.
In the top navigation bar, select the region where ECS01 is deployed.
Click Create and set the following parameters.
Parameter
Description
Instance Configuration Source
Select Create from Scratch.
Minimum Number of Instances
Set to 1. Auto Scaling scales out if the instance count falls below this value.
Maximum Number of Instances
Set to 2. Auto Scaling scales in if the instance count exceeds this value. In this example, at most one additional ECS instance is added to the server group.
Default cooldown (seconds)
Set to 0 for this example. After a scaling activity completes, Auto Scaling waits this long before triggering the next one. Adjust based on how long your instances need to warm up.
VPC and vSwitch
Select the same VPC and vSwitch as ECS01.
Associate CLB Instance
Select the CLB server group, then specify a port and a weight for the instances.
Set any remaining parameters based on your requirements and click Create.
Step 2: Create a scaling configuration
A scaling configuration is the template Auto Scaling uses when creating new ECS instances. Set it to mirror ECS01 so that new instances are deployment-ready.
On the Scaling Groups page, find the scaling group you created and click Details in the Actions column.
On the Instance Configuration Sources tab, click Scaling Configurations, then click Create Scaling Configuration.
Set the following parameters.
Parameter
Description
Billing Method
Select Pay-as-you-go.
Instance Configuration Mode
Select Specify Instance Type.
Select Instance Type
Select the same instance type as ECS01.
Select Image
Select the custom image created from ECS01.
Security Group
Select the same security group as ECS01.
Click Create. In the Preview Scaling Configuration dialog box, click Confirm.
In the The scaling configuration is created dialog box, click Enable Configuration to activate the configuration and enable the scaling group.
Step 3: Create scaling rules
Scaling rules define what happens when a scaling event fires — how many instances to add or remove. Create one rule for scale-out and one for scale-in.
Create the scale-out rule:
On the Scaling Groups page, click Details for your scaling group. On the Scaling Rules and Event-triggered Tasks tab, click Scaling Rules.
Click Create Scaling Rule and set the following parameters, then click OK.
Parameter
Description
Rule Name
Enter a descriptive name, such as
Automatically Adds One ECS Instance.Rule Type
Select Simple Scaling Rule.
Scaling Activity
Select Add 1 Instance.
Create the scale-in rule:
Click Create Scaling Rule again and set the following parameters, then click OK.
Parameter
Description
Rule Name
Enter a descriptive name, such as
Automatically Removes One ECS Instance.Rule Type
Select Simple Scaling Rule.
Scaling Activity
Select Remove 1 Instance.
Step 4: Create event-triggered tasks
Event-triggered tasks link CloudMonitor metrics to your scaling rules. When a metric crosses the threshold you define, Auto Scaling executes the associated rule. Create one task to handle traffic spikes and one to scale in when load drops.
Create the scale-out task:
In the left-side navigation pane, click Event-triggered Tasks.
On the Alert Task page, click the System Monitoring tab, then click Create Event-triggered Task.
Set the following parameters and click OK.
Parameter
Description
Name
Enter a descriptive name, such as
Automatically Adds One ECS Instance.Resource Monitored
Select the scaling group created in Step 1.
Alert Condition
Set to CPU Utilization, Maximum (Maximum) >= 60%. When ECS01 sustains high CPU load, this fires the scale-out rule to add capacity.
Reference Period
Select 1 Minute. CloudMonitor evaluates the metric every minute.
Trigger After
Select 1 Times. The task fires after the threshold is breached once in the reference period.
Scaling Rule Triggered Upon Alerting
Select the scale-out rule created in Step 3.
Create the scale-in task:
Click Create Event-triggered Task again. Set the following parameters and click OK.
Parameter
Description
Name
Enter a descriptive name, such as
Automatically Removes One ECS Instance.Resource Monitored
Select the scaling group created in Step 1.
Alert Condition
Set to CPU Utilization, Maximum (Maximum) <= 30%. When load drops, this fires the scale-in rule to remove the extra instance and reduce costs.
Reference Period
Select 1 Minute.
Trigger After
Select 1 Times.
Scaling Rule Triggered Upon Alerting
Select the scale-in rule created in Step 3.
Step 5: Add ECS01 to the scaling group
Add ECS01 to the scaling group so that CloudMonitor can track its CPU utilization and trigger the event-triggered tasks you created.
On the Scaling Groups page, click Details for your scaling group.
On the Instances tab, click the Add Existing Instance tab, then click Add.
Select ECS01 and click Add.
ECS01 appears on the Manually Added tab when the operation completes.
Step 6: Verify automatic scaling
Run a stress test to trigger the scale-out task, then confirm that an ECS instance is added to the CLB server group. After the test ends, verify that the instance is automatically removed.
This example uses Alibaba Cloud Linux 3.2104. Your environment and results may differ.
Trigger scale-out:
Log on to ECS01 and run the following command to install the stress testing tool:
sudo yum install -y stressRun the following command to stress the CPU for 60 seconds:
sudo stress --cpu 1 --io 4 --vm 2 --vm-bytes 128M --timeout 60s &Return to the Alert Task page and wait a few minutes until the Status of the scale-out task changes to Alert.
Verify scale-out in Auto Scaling:
Go to the Scaling Groups page. Check that the Total Instances count in the Instances/Capacity column has increased by one. This confirms that Auto Scaling created a new instance and added it to the scaling group.
Verify scale-out in CLB:
Log on to the CLB console.
In the left-side navigation pane, choose .
Click the ID of the server group, and click the vServer groups tab. Confirm that the server group now contains two backend servers. The instance added by Auto Scaling has a name in the
ESS-XXformat.
Verify scale-in:
After the stress test ends, monitor the CPU utilization of ECS01. When it drops below 30%, the scale-in task fires.
Check the Scaling Groups page in the Auto Scaling console and the vServer groups tab in the CLB console to confirm that the extra ECS instance is removed.
What's next
For an overview of Auto Scaling and its core concepts, see What is Auto Scaling?
To schedule scaling in advance for predictable traffic patterns, see Configure instance numbers by using scheduled tasks.
To use target tracking or step scaling instead of simple scaling rules, see Configure scaling rules.