Use Auto Scaling to scale a CLB server group

Updated at:
Copy as MD

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:

image

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.

  1. Log on to the Auto Scaling console.

  2. Log on to the Auto Scaling console.

  3. In the left-side navigation pane, click Scaling Groups.

  4. In the top navigation bar, select the region where ECS01 is deployed.

  5. 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.

  6. 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.

  1. On the Scaling Groups page, find the scaling group you created and click Details in the Actions column.

  2. On the Instance Configuration Sources tab, click Scaling Configurations, then click Create Scaling Configuration.

  3. 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.

  4. Click Create. In the Preview Scaling Configuration dialog box, click Confirm.

  5. 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:

  1. On the Scaling Groups page, click Details for your scaling group. On the Scaling Rules and Event-triggered Tasks tab, click Scaling Rules.

  2. 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:

  1. 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:

  1. In the left-side navigation pane, click Event-triggered Tasks.

  2. On the Alert Task page, click the System Monitoring tab, then click Create Event-triggered Task.

  3. 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:

  1. 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.

  1. On the Scaling Groups page, click Details for your scaling group.

  2. On the Instances tab, click the Add Existing Instance tab, then click Add.

  3. 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:

  1. Log on to ECS01 and run the following command to install the stress testing tool:

    sudo yum install -y stress
  2. Run the following command to stress the CPU for 60 seconds:

    sudo stress --cpu 1 --io 4 --vm 2 --vm-bytes 128M --timeout 60s &
  3. 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:

  1. 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:

  1. Log on to the CLB console.

  2. In the left-side navigation pane, choose CLB > Instances.

  3. 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-XX format.

Verify scale-in:

  1. After the stress test ends, monitor the CPU utilization of ECS01. When it drops below 30%, the scale-in task fires.

  2. 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