This topic describes how to use Auto Scaling to scale elastic container instances in an efficient manner.
Background information
This topic provides examples on how to use Auto Scaling to scale elastic container instances. Company A is used in this topic. The operations required to scale elastic container instances vary based on different business scenarios. The following table describes the requirements and operations required in different business scenarios.
Business scenario | Requirement | Operation |
---|---|---|
Stable demand | Requirement 1: At least two elastic container instances are required to meet daily business requirements. Each elastic container instance must have 4 vCPUs and 8 GiB memory. | |
Unpredictable increase in demand |
| |
Predictable increase in demand from 18:00 to 22:00 every day |
|
Preparations
The first time you use Auto Scaling, you must make the following preparations:
- The AliyunServiceRoleForAutoScaling role is created.
- If you use Auto Scaling as a RAM user, you must attach the AliyunESSFullAccess policy to the RAM user.
For more information, see Manage the service-linked role for Auto Scaling.
Step 1: Create a scaling group
A scaling group is a group of instances that can meet your business requirements. Scaling group is the core unit in Auto Scaling. Auto Scaling automatically adds instances to or removes instances from scaling groups.
- Log on to the Auto Scaling console.
- In the left-side navigation pane, click Scaling Groups. In this example, the operations are performed on the Scaling Groups page. If you do not have Auto Scaling resources in the region that you specify, a welcome page is displayed after you log on to the Auto Scaling console. Follow the on-screen instructions to create Auto Scaling resources.
- In the top navigation bar, select the region where Auto Scaling is activated.
- In the upper-left corner of the Scaling Groups page, click Create.
- Configure parameters of the scaling group and click OK.
The following table describes the parameters that are used in this example. For parameters that are not described in the following table, use the default settings.
Parameter Example Description Scaling Group Name Enter MyFirstECIScalingGroup. None Type Set the value to ECI. A value of ECI specifies that the scaling group contains only elastic container instances. Instance Configuration Source Set the value to Create from Scratch. After you create the scaling group, you must create a scaling configuration. Minimum Number of Instances Set the value to 2. The scaling group must contain at least two elastic container instances to meet Requirement 1 of Company A.
If the number of elastic container instances in the scaling group is less than two, Auto Scaling automatically creates an elastic container instance to meet the required minimum number of instances.
Maximum Number of Instances Set the value to 5. The scaling group can contain up to five elastic container instances. Auto Scaling automatically removes excess instances from the scaling group to help Company A reduce costs. VPC Select vpc-bp1jmxxau0lur929p****. The VPC and vSwitch of the scaling group that you want to create. For information about how to create a VPC and a vSwitch, see Create a VPC with an IPv4 CIDR block. vSwitch Select vsw-bp155oak33mqngov2****. - In the Create Scaling Group dialog box, click OK.
Step 2: Create a scaling configuration
A scaling configuration is a template that describes information about the instance configuration, such as the instance type, disk, public IP address, and security group. You can use a scaling configuration to create elastic container instances during scale-outs. Auto Scaling uses the scaling configuration to create elastic container instances that have the same configurations.
- Find a scaling group and use one of the following methods to go to the scaling group details page:
- Click the ID of the scaling group in the Scaling Group Name/ID column.
- Click Details in the Actions column.
- In the upper part of the scaling group details page, click the Instance Configuration Sources tab.
- On the Scaling Configurations tab, click Create Scaling Configuration.
- In the Basic Settings step and Other Settings (Optional) step, configure parameters as prompted. In the Confirm step, click Create.
The following table describes the parameters that are used in this example. For parameters that are not described in the following table, use the default settings.
Step Parameter Example Description Basic Settings Billing Method Set the value to Pay-as-you-go. Auto Scaling is free of charge. However, you are charged for the elastic container instances that are added to the scaling group based on the pricing of the Elastic Container Instance service. For more information, see Billing overview. Security Group Select sg-bp18kz60mefsicfg****. Select an existing security group. For information about how to create a security group, see Create a security group. Container Group Configurations - vCPU: Select 4 vCPUs.
- Memory: Select 8 GiB.
- Name: Enter container-group-a.
All containers in the container group share the resources of the container group. Note In this example, the cost optimization feature is disabled. For information about the cost optimization feature, see Enable the cost optimization feature for scaling groups of the Elastic Container Instance type.Container Configurations - Container Name: Enter container-1.
- Image:
- Select Container Image: Select eci_open/centos on the Common Images tab.
- Select Image Tag: Select 7.
- Image Pull Policy: Set this parameter to Always or If Not Present.
- Startup Command:
- Executable Command: Enter sleep.
- Parameter: Enter 999999.
The image that runs on the container and the startup command of the container. Other Settings (Optional) Scaling Configuration Name Enter MyFirstECIScalingConfiguration None - In the Success message, click Enable.
- In the Enable Scaling Configuration message, click OK.
In a scaling group, you must enable one scaling configuration. After you enable the scaling configuration, the scaling configuration enters the Active state.
- In the Enable Scaling Group message, click OK.
You must enable the scaling group. This allows Auto Scaling to add or remove instances to or from the scaling group.
Note In this example, Auto Scaling creates two elastic container instances to meet Requirement 1 of Company A. For information about how to view the instances in a scaling group, see View the instances in a scaling group.
Step 3: Create a scaling rule
A scaling rule specifies the action that adds instances to or removes instances from a scaling group. The scaling rule can also help you determine the required minimum or maximum number of instances in a scaling group.
In this example, the following scaling rules are created to meet the business requirements:
- Scale-out rule: adds one elastic container instance.
- Scale-in rule: removes one elastic container instance.
After you create the preceding scaling rules, you can trigger scaling activities. You can manually execute scaling rules to trigger scaling activities. You can also create scheduled tasks or event-triggered tasks to allow Auto Scaling to execute scaling rules.
- In the upper part of the scaling group details page, click the Scaling Rules and Event-triggered Tasks tab.
- On the Scaling Rules tab, create a scale-out rule.
- On the Scaling Rules tab, create a scale-in rule.
Step 4: Create an event-triggered task
Event-triggered tasks monitor specific metrics to collect metric values in real time. When metric values meet the alert conditions, alerts are triggered to execute specified scaling rules. In this example, the following event-triggered tasks are created to meet Requirement 2 and Requirement 3 of company A:
- To meet Requirement 2, create an event-triggered task named EventTriggeredECIScalingOut. When the average CPU utilization reaches or exceeds 70%, Auto Scaling automatically executes the scaling rule that adds one elastic container instance to the scaling group.
- To meet Requirement 3, create an event-triggered task named EventTriggeredECIScalingIn. When the average CPU utilization reaches or drops below 20%, Auto Scaling automatically executes the scaling rule that removes one elastic container instance from the scaling group.
- In the upper part of the scaling group details page, click the Scaling Rules and Event-triggered Tasks tab, and then click the Scheduled and Event-triggered Tasks tab.
- Click the Event-triggered Tasks (System) tab. In this example, system metrics are used. If you click the Event-triggered Tasks (Custom) tab, you must publish your custom metrics to CloudMonitor before you create the event-triggered task. For more information, see Custom monitoring event-triggered tasks.
- Create an event-triggered task for a scale-out.
- Create an event-triggered task for a scale-in.
Step 5: Create a scheduled task
- To meet Requirement 4, create a scheduled task named ScheduledECIScalingOut for peak hours. This task triggers the scaling rule that adds one elastic container instance to the scaling group.
- To meet Requirement 5, create a scheduled task named ScheduledECIScalingIn for off-peak hours. This task triggers the scaling rule that removes one elastic container instance from the scaling group.
- In the upper part of the scaling group details page, click the Scaling Rules and Event-triggered Tasks tab.
- Click the Scheduled and Event-triggered Tasks tab.
- On the Scheduled Task tab, create a scheduled task for a scale-out.
- On the Scheduled Task tab, create a scheduled task for a scale-in.
Result
Auto Scaling automatically scales elastic container instances based on your configurations to meet the following requirements:
- After you enable the scaling group, Auto Scaling automatically adds two elastic container instances to meet Requirement 1.
- If the average CPU utilization of the elastic container instances in the scaling group reaches or exceeds 70%, Auto Scaling automatically adds one elastic container instance to meet Requirement 2.
- If the average CPU utilization of the elastic container instances in the scaling group reaches or drops below 20%, Auto Scaling automatically removes one elastic container instance from the scaling group to meet Requirement 3.
- Auto Scaling adds one elastic container instance at 17:55:00 every day to meet Requirement 4.
- Auto Scaling removes one elastic container instance from the scaling group at 22:05:00 every day to meet Requirement 5.
On the Instances tab, you can view the added elastic container instances. The configurations of the scaling configuration used by the scaling group are the same as the configurations of the automatically created elastic container instances. For more information, see View the instances in a scaling group.
