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 configurations based on business needs.

Prerequisites

  • Before you associate a scaling group with SLB instances, make sure 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, make sure 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 a 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 > Create Scaling Group 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.
      Parameter Description
      Maximum Number of Instances When the number of existing ECS instances is greater than the maximum number of instances, Auto Scaling automatically removes ECS instances from the scaling group to maintain the maximum number.
      Minimum Number of Instances When the number of existing ECS instances is less than the minimum number of instances, Auto Scaling automatically adds instances to the scaling group to maintain the minimum number.
      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 Cloud Monitor. However, scaling activities triggered by other types of tasks, such as scheduled tasks and manually executed tasks, are not subject to the cooldown time and are executed immediately.
    4. Optional:Specify the instance removing policy.
      This policy is used to filter and remove ECS instances from a scaling group based on multiple filter conditions. If multiple ECS instances meet the conditions of the policy, one instance is removed at random.
      The Instance Removing Policy parameter contains Filter First and Then Remove from Results. You cannot specify the same value for Filter First and Then Remove from Results. The following table describes the options for the instance removing policy.
      Option Description
      Earliest Instance Created Using Scaling Configuration The scaling configuration refers to the instance configuration source that contains the scaling configuration and instance launch template.

      Auto Scaling filters instances to find the ones that use the earliest scaling configuration and instance launch template. Manually added instances are not associated with scaling configurations or instance launch templates. Therefore, manually added instances are not found first. If all associated instances have been removed but Auto Scaling must remove more instances from the scaling group, manually added instances are removed at random.

      The version of an instance launch template does not 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 to find the ones that were created at the earliest points in time.
      Most Recent Created Instance Auto Scaling filters instances to find the ones that were created most recently.
      No Policy This option is available only for Then Remove from Results. This option indicates that Auto Scaling does not filter instances in the second step.
      For example, if Auto Scaling filters instances based on Earliest Instance Created Using Scaling Configuration in the first step, then you can select one of the following options in the second step:
      • No Policy: This option indicates that Auto Scaling does not filter instances in the second step.
      • Earliest Created Instance: Auto Scaling filters instances to find the ones that were created at the earliest points in time from the filtering results in the first step.
      • Most Recent Created Instance: Auto Scaling filters the instances to find the ones that were created most recently from the filtering results in the first step.
    5. Optional:Enable deletion protection for the scaling group.
      After this feature is enabled, the scaling group cannot be deleted from the console or through API operations.
    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 of instances within the scaling group Description
      VPC
      • When you create a scaling configuration, you can select only instance types that support VPCs.
      • When you manually add existing ECS instances to the scaling group, you can select only instances that are located 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 to the scaling group, you can select only instances that are located in the classic network.
    2. Optional:If the network type of instances within the scaling group is VPC, configure the following parameters:
      • Network type: 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 the highest 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 balanced distribution policy takes effect only when the scaling group is associated with multiple VSwitches that are distributed across more than two zones. The policy 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 cost optimization 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 pay-as-you-go ECS instances. 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 automatically created instances. 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 by using the lowest cost instance types.
        Enable Supplemental Preemptible Instances After the Supplemental Preemptible Instances feature is enabled, Auto Scaling automatically creates 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 Descripition
        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 charged for these resources. However, you are still charged for other resources such as disks and elastic IP addresses (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 are reassigned 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 creates 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, depending on whether their instance types meet the requirement. If the ECS instances in the stopped instance pool cannot enter the Running state due to insuffcient qualified instances, Auto Scaling will release these instances and create a specific number of ECS instances that meet the instance type requirement to satisfy the desired capacity of the scaling group.

    3. Optional:Add existing instances.
      If you specify the expected number of instances and then add existing instances, the expected number of instances automatically increases. 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 lifecycle, Auto Scaling automatically releases 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 are 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 routing methods, 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 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: