Auto Scaling is interfaced with Network Load Balancer (NLB) to automatically scale in or scale out server groups for NLB. After you create an event-triggered task, Auto Scaling can dynamically add or remove Elastic Compute Service (ECS) from server groups of NLB. This ensures the availability of NLB 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 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 NLB server group. After a scaling group is associated with an NLB server group, the creation and removal of ECS instances by the system or by you are synchronized with the NLB 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, NLB distributes requests to ECS01 based on forwarding rules. If the CPU usage of ECS01 reaches the specified threshold, more 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 a specified threshold, the ECS instances are removed from the server group and deleted.
Prerequisites
At least one NLB instance is created and running. For more information, see Create and manage an NLB instance.
A server group is created and available, backend servers are added to the server group, and health checks are enabled for the server group. In this example, the server group is named RS1, and the backend server is named ECS01.
A custom image is created for ECS01. For more information, see Create a custom image from an instance.
At least one listener is created for the NLB instance. For more information, see Add a TCP listener.
The NLB instance and the scaling group are in the same virtual private cloud (VPC).
Step 1: Create a scaling group
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 Auto Scaling is activated.
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 minimum number of instances allowed, Auto Scaling automatically scales out until the number of the instances is equal to the minimum number allowed. The parameter is set to 1 in this example. This ensures that the scaling group contains at least one ECS instance (ECS01).
Maximum Number of Instances
If the number of instances in a scaling group is greater than the maximum number of instances allowed, Auto Scaling automatically scales in until the number of the instances is equal to the maximum number allowed. The parameter is set to 2 in this example. In addition to ECS01, only one more ECS instance can be added to the scaling group.
Cooldown Time
The scaling group does not perform any scaling activities during the cooldown period after a scaling activity is performed to add or remove ECS instances. Currently, the setting is available only for event-triggered (CloudMonitor) tasks. This parameter is set to 0 in this example. You can change the 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.
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 a scaling group
On the Scaling Groups page, click Details in the Actions column. On the Instance Configuration Sources tab, click Scaling Configurations.
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. Pay-as-you-go is selected in this example.
Instance Configuration Mode
Specify Instance Type is selected in this example.
Select Instance Type
The instance type of ECS01 is selected in this example.
Select Image
The custom image of ECS01 is selected in this example.
Security Group
The security group of ECS01 is selected in this example.
Click Create and then click Create in the Preview Scaling Configuration message.
In the The scaling configuration is created dialog box, click Enable to enable the configuration and scaling group.
Step 3: Create a scaling rule
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.
Create an automatic scale-out rule. On the Scaling Rules tab, click Create Scaling Rule and set the parameters. The following table describes some of the parameters. Set the other parameters based on business requirements. 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.
Create an automatic scale-in rule. On the Scaling Rules tab, click Create Scaling Rule and set the parameters. The following table describes some of the parameters. Set the other parameters based on your business requirements. 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
In the left-side navigation pane, choose
.On the Event-triggered Task page, click the System Monitoring tab and click Create Event-triggered Task.
Create an event-triggered task that triggers an automatic scale-out. Click Create Event-triggered Task and set the parameters. The following table describes some of the parameters. Set the other parameters based on your business requirements. Click OK.
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.
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: Add an existing ECS instance to the scaling group for monitoring
Auto Scaling needs to monitor ECS instances in scaling groups and adjusts the number of ECS instances based on monitoring data and event-triggered tasks. Therefore, you must add existing ECS instances to the scaling group so that Auto Scaling can monitor the ECS instances.
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.
Click Add Existing Instance. In the dialog box that appears, select ECS01 and click Add.
You can find ECS01 on the Manually Added tab.
Step 6: 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 NLB server group. You can check whether an ECS instance is added to the server group in the NLB 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.
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
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 &
Return to the Scaling Groups page and wait a few minutes until the status of the event-triggered task is Alert.
Go to the Scaling Groups page. You can view that the total number of instances displayed in the Instances/Capacity column is one more before the scale-out activity. This indicates that an ECS instance is created and added to the scaling group.
- Log on to the NLB console.
In the left-side navigation pane, choose
.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 one named
ESS-XX
is the ECS instance that is added by Auto Scaling.After the 60-second stress test ends, you can log on to the Auto Scaling console and NLB console to check whether the ECS instance is automatically removed from the server group.
References
For more information about Auto Scaling, see What is Auto Scaling?
Auto Scaling supports scheduled tasks that can automatically scale servers. For more information, see Configure instance numbers by using scheduled tasks.
Auto Scaling is interfaced with CloudMonitor to support advanced features, such as resource scaling based on monitoring metrics and predictive metric values. For more information, see Manage scaling rules.