All Products
Search
Document Center

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

Last Updated:Mar 06, 2024

Auto Scaling is integrated 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.

Example

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 that allows CloudMonitor to monitor 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 the health check status to ensure high service 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

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 named RS1 and the ECS instance is named 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.

    Minimum Number of Instances

    If the number of instances in a scaling group is less than the specified minimum number of instances, Auto Scaling automatically scales out until the number of the instances reaches the minimum number. In this example, 1 is selected, which specifies that at least one ECS instance is required.

    Maximum Number of Instances

    If the number of instances in a scaling group is greater than the specified maximum number of instances, Auto Scaling automatically scales in until the number of the instances reaches the maximum number. In this example, 2 is selected, which specifies that at most one more ECS instance can be added to the server group.

    Default Cooldown Time

    After a scale-in or scale-out activity is completed, the next scale-in or scale-out activity does not start until the specified cooldown time ends. This parameter is available only to event-triggered tasks. In this example, 0 is selected. Specify a value based on your business requirements.

    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 your business requirements and click OK. You can view the scaling group on the Scaling Groups page.

Step 2: Create a configuration template for the 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 your business requirements.

    Parameter

    Description

    Billing Method

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

    Instance Configuration Mode

    In this example, Specify Instance Type is selected.

    Select Instance Type

    In this example, the type of ECS01 is selected.

    Select Image

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

    Security Group

    In this example, the security group of ECS01 is selected.

  3. Click Create. In the Preview Scaling Configuration message, click Create.

  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

    In this example, Simple Scaling Rule is selected.

    Operation

    In this example, Add 1 Instance is selected.

  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

    In this example, Simple Scaling Rule is selected.

    Operation

    In this example, Remove 1 Instance is selected.

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

    In this example, 1 Minute is selected.

    Triggered After

    In this example, 1 Times is selected.

    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

    In this example, 1 Minute is selected.

    Triggered After

    In this example, 1 Times is selected.

    Trigger Rule

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

Step 5: Add ECS instances to the scaling group

Auto Scaling automatically adjusts the number of backend servers based on monitoring data and the event-triggered tasks. Therefore, you must add the ECS instances that you want to monitor to the scaling group.

  1. On the Scaling Groups page, find the scaling group that you want to manage and click Details in the Actions column. On the Instances tab, click the Manually Added tab.

  2. Then, click Add Existing Instance. On the page that appears, select ECS01 and click Add.

  3. You can view ECS01 on the Manually Added tab.

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

Use a stress testing 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 testing 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 becomes Alert.

  4. Go to the Scaling Groups page. You can view that the total number of instances displayed in the Instances/Capacity column is increased 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 ESS-XX format is added by Auto Scaling.

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