If your business loads fluctuate frequently or have a fixed scaling pattern, we recommend that you use Auto Scaling to implement automatic scaling. After a scaling group is created based on an ECS instance, Auto Scaling automatically adds or removes a group of ECS instances that use the same scaling configuration based on business needs.

Prerequisites

  • Before you associate a scaling group with SLB instances, ensure that the following conditions are met:
    • You have at least one SLB instance in the Running state. For more information, see Create an SLB instance.
    • The SLB instance and the scaling group are in the same region.
    • The SLB instance and the scaling group are in the same Virtual Private Cloud (VPC) network if their network type is VPC.
    • If the network type of the SLB instance is classic network, the network type of the scaling group is VPC, and the back-end server group of the SLB instance contains VPC-connected ECS instances, then the ECS instances and the scaling group must be in the same VPC network.
    • At least one listener is configured on the SLB instance. For more information, see Listener overview.
    • Health check is enabled on the SLB instance. For more information, see Configure health check.
  • Before you associate a scaling group with ApsaraDB for RDS instances, ensure that the following conditions are met:
    • At least one ApsaraDB for RDS instance is in the Running state. For more information, see What is ApsaraDB for RDS?.
    • The ApsaraDB for RDS instances and the scaling group must reside in the same region.

Background information

You can create a scaling group based on an ECS instance regardless of the billing method of the instance. A subscription, pay-as-you-go, or preemptible instance can all be used as a scaling configuration source.

After the scaling group is created, you can manually add existing ECS instances or use Auto Scaling to automatically create ECS instances. Only pay-as-you-go and preemptible ECS instances can be automatically created. However, you can manually add existing ECS instances of any billing method.

For more information about the limits of a scaling group, see Limits.

Procedure

  1. Log on to the ECS console.
  2. In the left-side navigation pane, choose Instances & Images > Instances.
  3. In the top navigation bar, select a region.
  4. Find the ECS instance that you want to use as a scaling configuration source, and choose More > Deployment & Elasticity > New auto scaling in the Actions column.
  5. On the Create Scaling Group page, view the scaling configuration source.
    When you create a scaling group based on an ECS instance, the Select Existing Instance option and the ECS instance are automatically selected in the Source Type section on the Create Scaling Group page. Keep these settings unchanged.
  6. Configure basic information of the scaling group.
    1. Specify the scaling group name.
    2. Specify the number of instances in the scaling group.
      Type Description
      Maximum Number of Instances When the upper limit of ECS instances is reached, Auto Scaling automatically removes instances to ensure that the number of instances in the scaling group matches the upper limit.
      Minimum Number of Instances When the lower limit of ECS instances is reached, Auto Scaling automatically adds instances to ensure that the number of instances in the scaling group matches the lower limit.
      Expected Number of Instances Auto Scaling automatically keeps the number of ECS instances at the expected level. For more information, see Expected Instances.
    3. Specify the default cooldown time.
      The Default Cooldown Time parameter specifies the default cooldown time of a scaling group in seconds. During the cooldown time, the scaling group rejects all scaling activity requests triggered by event-triggered tasks from CloudMonitor. However, some scaling activities are not subject to the cooldown time and are executed immediately. These scaling activities are triggered by other types of tasks such as scheduled tasks and manually executed tasks.
    4. Optional:Specify the instance removing policy.
      When ECS instances are no longer required, you can specify the policy to remove the instances. If multiple ECS instances meet the conditions of the policy, one instance is removed at random. The Instance Removing Policy parameter contains two fields.
      Configuration Option Description
      Valid values for the first field Earliest Instance Created Using Scaling Configuration The scaling configuration refers to the instance configuration source that contains the scaling configuration and launch template.

      Auto Scaling filters the instances that use the earliest scaling configuration and launch template. Manually added instances are not associated with a scaling configuration or launch template. Therefore, manually added instances are not filtered first. If all associated instances have been filtered but the scaling group needs to remove more instances, manually added instances are removed at random.

      The version of a launch template does not necessarily indicate the order in which the template was added. For example, you select the lt-foress V2 template when you create a scaling group. Then, you select the lt-foress V1 template to modify the scaling group. The scaling group considers the lt-foress V2 launch template as the template that was added earlier.

      Earliest Created Instance Auto Scaling filters instances that were created at the earliest points in time.
      Most Recent Created Instance Auto Scaling filters instances that were created most recently.
      Valid values for the second field No Policy Auto Scaling does not filter instances.
      Earliest Created Instance Auto Scaling filters instances that were created at the earliest points in time from the filtering results in the first step.
      Most Recent Created Instance Auto Scaling filters instances that were created most recently from the filtering results in the first step.

      By default, Auto Scaling filters instances that were created based on the earliest scaling configuration. From the filtering results, Auto Scaling filters and removes the instances that were created at the earliest points in time.

    5. Optional:Enable deletion protection for the scaling group.
      After this feature is enabled, the scaling group cannot be deleted by using the console or API.
    6. Add tags.
      You can add tags to search for and manage scaling groups. For more information, see Overview.
  7. Specify the scaling configuration.
    1. View the network type.
      Notice Keep the default network type unchanged. Otherwise, the creation fails.
      Network type Description
      VPC
      • When you create a scaling configuration, you can select only instance types that support VPC.
      • When you manually add existing ECS instances, you can select only instances in the same VPC as the scaling group.
      Classic Network
      • When you create a scaling configuration, you can select only instance types that support the classic network.
      • When you manually add existing ECS instances, you can select only instances in the classic network.
    2. Optional:If the network type is VPC, configure the required parameters.
      • VPC
        Note Keep the default VPC unchanged. Otherwise, the creation fails.
      • VSwitch

        A VSwitch can belong only to one zone. To deploy ECS instances across multiple zones, you must specify multiple VSwitches that belong to different zones. We recommend that you select multiple zones to reduce the risk of insufficient resources and increase the success rate of creating ECS instances.

      • Multi-zone scaling policy
        Notice The multi-zone scaling policy cannot be modified after the scaling group is created.
        Policy Description
        Priority Policy The VSwitch that is first selected has a higher priority. When an ECS instance cannot be created in the zone where the VSwitch with the highest priority resides, Auto Scaling automatically uses the VSwitch that has the second highest priority to create the ECS instance.
        Balanced Distribution Policy The policy takes effect only when the scaling group is associated with multiple VSwitches that are distributed across more than two zones. It evenly distributes ECS instances across zones where the VSwitches reside. If the ECS instances are not evenly distributed across zones due to insufficient resources, you can use the Rebalance Distribution feature to evenly distribute the ECS instances. For more information, see Rebalance the distribution of ECS instances.
        Cost Optimization Policy The policy takes effect only when you specify multiple instance types in the scaling configuration. Auto Scaling creates ECS instances based on the unit prices of vCPUs in ascending order.

        If you select Preemptible Instance as the billing method in the scaling configuration, preemptible instances are preferentially created. When preemptible instances cannot be created due to insufficient resources, Auto Scaling automatically attempts to create pay-as-you-go instances.

        If you select Cost Optimization Policy, you can set the parameters listed in the following table to enable the scaling policy that involves both pay-as-you-go and preemptible instances.
        Parameter Description
        Minimum Pay-as-you-go Instances The minimum number of ECS instances that use the pay-as-you-go billing method. Default value: 0. If the number of pay-as-you-go ECS instances in the scaling group is less than this value, Auto Scaling preferentially creates pay-as-you-go instances.
        Percentage of Pay-as-you-go Instances The percentage of pay-as-you-go ECS instances among all instances that are created automatically. Default value: 70%. The percentage is calculated based on the difference between the total number of instances and the minimum number of pay-as-you-go instances.
        Lowest Cost Instance Types The number of instance types with the lowest cost. Default value: 1. This parameter takes effect when multiple instance types are specified in the scaling configuration. When preemptible instances are created, Auto Scaling evenly creates ECS instances from the lowest cost instance types.
        Enable Supplemental Preemptible Instances After the Supplemental Preemptible Instances feature is enabled, Auto Scaling automatically creates new preemptible instances five minutes before the existing instances are reclaimed.
      • Instance reclaim mode
        Notice The reclaim mode cannot be modified after the scaling group is created.
        Mode Description
        Release Mode When a scale-in event is triggered, Auto Scaling automatically releases a specific number of ECS instances. When a scale-out event is triggered, Auto Scaling automatically creates a specific number of ECS instances for the scaling group.
        Shutdown and Reclaim Mode This mode can improve scaling efficiency.
        When a scale-in event is triggered, the status of the removed ECS instances becomes No Fees for Stopped Instances (VPC-Connected), and their vCPUs, memory, and public IP addresses are reclaimed. You are no longer billed for these resources. However, you are still billed for other resources such as disks and EIPs. For more information, see No Fees for Stopped Instances (VPC-Connected). These stopped ECS instances form a stopped instance pool.
        Note If the ECS instances have public IP addresses before they enter the No Fees for Stopped Instances (VPC-Connected) state, the instances will be reassigned with public IP addresses when they are restarted, and the addresses may be different from the previous ones.

        When a scale-out event is triggered, the ECS instances in the stopped instance pool preferentially enter the running state. If these instances are still insufficient, Auto Scaling will create more ECS instances.

        When a scale-out event is triggered, the ECS instances in the stopped instance pool may or may not enter the running state. If the ECS instances in the stopped instance pool cannot enter the running state due to insufficient resources, Auto Scaling will release these instances and create a specific number of ECS instances.

    3. Optional:Add existing instances.
      If you specify the expected number of instances and then add existing instances, the expected number of instances will automatically increase. For example, when you create a scaling group, you set the expected number of instances to one and then add two existing instances. After the scaling group is created, two existing instances are added to the scaling group, and the expected number of instances becomes three.
      You can enable the scaling group to manage the instance lifecycle.
      • If you select Enable the scaling group to manage the instance lifecyle, Auto Scaling will automatically release the ECS instances that are manually removed from the scaling group or automatically removed due to being unhealthy.
      • If you do not select Enable the scaling group to manage the instance lifecyle, the ECS instances that are removed from the scaling group will not be automatically released.
  8. Optional:Configure advanced settings.
    You can associate only a limited number of SLB and ApsaraDB for RDS instances with a scaling group. For more information, see Limits.
    1. Associate SLB instances.
      After you associate SLB instances with the scaling group, ECS instances that are added to the scaling group will be automatically added as SLB backend servers. You can specify a server group for the ECS instances. The following table lists two available server groups.
      Server group Port number Weight Description
      Default server group You can specify the port number when you configure listeners for SLB instances. Default value: 50. You can set the weight to other values in the scaling configuration. The group of ECS instances that are used to receive requests. If the listener is not configured with a VServer group or a primary/secondary server group, requests are forwarded to the ECS instances in the default server group.
      VServer group You can specify the port number when you select a VServer group. Default value: 50. You can set the weight to other values when you select a VServer group. If you want to distribute different requests to different backend servers or configure domain name - or URL-based forwarding rules, you can use VServer groups.

      You can specify only a limited number of VServer groups for a scaling group. For more information, see Limits.

      Note If you specify the default server group and multiple VServer groups at the same time, ECS instances are added to all server groups.
    2. Associate ApsaraDB for RDS instances.
      After the ApsaraDB for RDS instances are specified, the internal IP addresses of ECS instances that are added to the scaling group are added to the whitelists of the ApsaraDB for RDS instances to allow for internal communication.
  9. Click Create Scaling Group.
  10. In the Create Scaling Group Status Wizard message, click View Scaling Groups.
    The newly created scaling group is displayed in the scaling group list. Auto Scaling automatically creates a scaling configuration for the scaling group, and the scaling group enters the Enabled state after it is created because an existing ECS instance is used as the scaling configuration source.
    • If the value of Minimum Number of Instances is greater than zero, Auto Scaling automatically creates ECS instances to ensure that the number of instances in the scaling group is no less than the minimum number of instances.
    • If the value of Expected Number of Instances is greater than zero, Auto Scaling automatically creates or removes ECS instances to ensure that the number of instances in the scaling group is equal to the expected number of instances.

What to do next

You can manually or use scheduled or event-triggered tasks to add or remove ECS instances in the scaling group. For more information, see: