All Products
Search
Document Center

Server Load Balancer:Use Auto Scaling to scale an ALB server group

Last Updated:Jan 18, 2024

Auto Scaling is interfaced with Application Load Balancer (ALB) to automatically scale in or scale out servers in server groups of ALB. After you create an event-triggered task, Auto Scaling can dynamically scale in or scale out Elastic Compute Service (ECS) in server groups of ALB. This ensures the availability of ALB and prevents resource waste.

Sample scenario

When a news website releases the latest news, the number of page views (PVs) may drastically increase and exceed the service capacity of the current servers. As a result, the servers may fail to respond to incoming requests. Users can load the web page when the workloads on the servers decrease as the news fades over time. User traffic fluctuations on this website are unpredictable, which makes workload management more difficult.

In this scenario, you can create an event-triggered task so that CloudMonitor can monitor the resource usage such as the CPU usage of ECS instances. This way, the system can automatically add ECS instances to or remove ECS instances from the ALB server group. After a scaling group is associated with an ALB server group, the scale-in and scale-out activities that are automatically or manually triggered for ECS instances in scaling groups are synchronized with the ALB server group. Requests are distributed to the ECS instances based on traffic volumes and health check status to ensure service high availability.

In the following example, ALB distributes requests to ECS01 based on forwarding rules. If the CPU usage of ECS01 reaches the specified threshold, ECS instances are created and added to the server group based on the scaling rule and event-triggered task. If the CPU usage of ECS01 drops below the specified threshold, ECS instances are removed from the server group and released.

image

Procedure

image

Prerequisites

  • At least one ALB instance is created and running. For more information, see Create an ALB instance.

  • A server group is created for the ALB instance and an ECS instance is added to the server group. The server group is in the Available state. In this example, the server group is referred to as RS1 and the ECS instance is referred to as ECS01.

  • A custom image is created for ECS01. For more information, see Create a custom image from an instance.

  • Health checks are enabled for the ALB instance. For more information, see Health checks.

  • At least one listener is created for the ALB instance. For more information, see Add an HTTP listener.

  • The ALB instance and the scaling group are deployed in the same virtual private cloud (VPC).

Step 1: Create a scaling group

  1. Log on to the Auto Scaling console.

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

  3. In the top navigation bar, select the region where Auto Scaling is activated.

  4. Go to the Auto Scaling page. You can create a scaling group or use an existing scaling group based on your business requirements. Click Create and set the parameters. The following table describes some of the parameters.

    Parameter

    Description

    Instance Configuration Source

    Select Create from Scratch.

    VPC and vSwitch

    Select the VPC and vSwitch of ECS01.

    Associate ALB and NLB Server Groups

    Select a server group and specify a port and a weight.

  5. Set the other parameters based on business requirements and click OK. You can view the scaling group on the Scaling Groups page.

Step 2: Create a configuration template for a scaling group

  1. On the Scaling Groups page, click Details in the Actions column. On the Instance Configuration Sources tab, click Scaling Configurations.

  2. On the Scaling Configurations tab, click Create Scaling Configuration and set the parameters. The following table describes some of the parameters. Set the other parameters based on business requirements.

    Parameter

    Description

    Billing Method

    Select a billing method for ECS instances. Pay-as-you-go is selected in this example.

    Instance Configuration Mode

    Specify Instance Type is selected in this example.

    Select Instance Type

    The type of ECS01, which is ecs.s6-c1m1.small, is selected in this example.

    Select Image

    In this example, the custom image of ECS01 is selected.

    Security Group

    The security group of ECS01 is selected in this example.

  3. Click Create and then click Create in the Preview Scaling Configuration message.

  4. In the The scaling configuration is created dialog box, click Enable to enable the configuration and scaling group.

Step 3: Create a scaling rule

  1. On the Scaling Groups page, find the scaling group that you want to manage and click Details in the Actions column. On the Scaling Rules and Event-triggered Tasks tab, click the Scaling Rules tab.

  2. Create an automatic scale-out rule. On the Scaling Rules tab, click Create Scaling Rule, set the following parameters, and then click OK.

    Parameter

    Description

    Rule Name

    Enter a name for the scaling rule, such as Automatically Adds One ECS Instance.

    Rule Type

    Simple Scaling Rule is selected in this example.

    Operation

    Add 1 Instance is selected in this example.

  3. Create an automatic scale-in rule. On the Scaling Rules tab, click Create Scaling Rule, set the following parameters, and then click OK.

    Parameter

    Description

    Rule Name

    Enter a name for the scaling rule, such as Automatically Removes One ECS Instance.

    Rule Type

    Simple Scaling Rule is selected in this example.

    Operation

    Remove 1 Instance is selected in this example.

Step 4: Create an event-triggered task and associate it with the scaling rule

  1. In the left-side navigation pane, choose Scaling Tasks > Event-Triggered Tasks.

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

  3. Create an event-triggered task that triggers an automatic scale-out. Click Create Event-triggered Task. In the dialog box that appears, set the parameters and click OK. The following table describes some of the parameters.

    Parameter

    Description

    Name

    Enter a name for the task, such as Automatically Adds One ECS Instance.

    Resource Monitored

    Select the scaling group created in Step 1.

    Alert Condition

    In this example, the alert condition is set to CPU Utilization, Maximum (Maximum) >= 60%.

    Statistical Period

    1 Minute is selected in this example.

    Triggered After

    1 Times is selected in this example.

    Trigger Rule

    Select the automatic scale-out rule created in Step 3.

  4. Create an event-triggered task that triggers an automatic scale-in. Click Create Event-triggered Task. In the dialog box that appears, set the parameters and click OK. The following table describes some of the parameters.

    Parameter

    Description

    Name

    Enter a name for the task, such as Automatically Removes One ECS Instance.

    Resource Monitored

    Select the scaling group created in Step 1.

    Alert Condition

    In this example, the alert condition is set to CPU Utilization, Maximum (Maximum) <= 30%

    Statistical Period

    1 Minute is selected in this example.

    Triggered After

    1 Times is selected in this example.

    Trigger Rule

    Select the automatic scale-in rule created in Step 3.

Step 5: Test whether backend servers can be automatically added and removed

Use a stress test tool to increase the CPU usage of ECS01 to 60% to trigger the event-triggered task so that an ECS instance can be created and added to the ALB server group. You can check whether an ECS instance is added to the server group in the ALB console. After the stress test ends and the CPU usage of ECS01 drops below 30%, check whether the event-triggered task is triggered again to automatically remove the ECS instance.

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

    sudo yum install -y epel-release 
    sudo yum install -y stress 
  2. Run the following command to perform a stress test on ECS01. The stress test lasts 60 seconds.

    sudo stress --cpu 1 --io 4 --vm 2 --vm-bytes 128M --timeout 60s &
  3. Return to the Scaling Groups page and wait a few minutes until the status of the event-triggered task is Alert.

  4. Go to the Scaling Groups page. You can view that the total number of instances displayed in the Instances/Capacity column increases by one after the scale-out activity. This indicates that an ECS instance is created and added to the scaling group.

  5. Log on to the ALB console.
  6. In the left-side navigation pane, choose ALB > Server Groups.

  7. Click the ID of the server group, and click the Backend Servers tab. On this tab, you can view that the server group contains two backend servers. The ECS instance named in the format of ESS-XX is added by Auto Scaling.

  8. After the 60-second stress test ends, you can log on to the Auto Scaling console and ALB console to check whether the ECS instance is automatically removed from the server group.