All Products
Search
Document Center

Elastic Compute Service:Create a scaling group based on an existing ECS instance

Last Updated:Mar 07, 2024

You can use scaling groups to automatically adjust the number of Elastic Compute Service (ECS) instances in response to load changes. You can create a scaling group based on an existing ECS instance. After the scaling group is created based on the ECS instance, the system creates a default scaling configuration for the scaling group. This simplifies the preparations required to enable the scaling group and makes the scaling group quickly ready for use. This topic describes how to create a scaling group based on an existing ECS instance.

Prerequisites

  • Make sure that the following requirements are met if you want to associate a Classic Load Balancer (CLB) instance with a scaling group:

    • One or more CLB instances are created. At least one CLB instance is in the Active state. For more information, see Create and manage a CLB instance.

    • The CLB instance must reside in the same region as the scaling group.

    • If the network type of the CLB instance and the scaling group is virtual private cloud (VPC), the CLB instance and the scaling group must reside in the same VPC.

    • If the network type of the CLB instance is classic network, the network type of the scaling group is VPC, and the backend server group of the CLB instance contains ECS instances or elastic container instances that reside in a VPC, the ECS instances and the scaling group must reside in the same VPC.

    • The CLB instance is configured with at least one listener. For information about how to configure listeners for CLB instances, see CLB listener overview.

    • The health check feature is enabled for the CLB instance. For information about how to enable the health check feature for CLB instances, see Configure and manage CLB health checks.

  • Make sure that the following requirements are met if you want to associate an Application Load Balancer (ALB) server group with a scaling group:

    • The network type of the scaling group must be VPC. The scaling group and the ALB server group must reside in the same VPC.

    • The ALB server group is in the Available state.

  • Make sure that the following requirements are met if you want to associate an ApsaraDB RDS instance with a scaling group:

    • One or more ApsaraDB RDS instances are created. At least one ApsaraDB RDS instance is in the Running state. For more information, see What is ApsaraDB RDS?

    • The ApsaraDB RDS instance must reside in the same region as the scaling group.

Background information

ECS instances can be used as configuration sources to create scaling groups regardless of instance billing methods. Subscription instances, pay-as-you-go instances, and preemptible instances can all be used as configuration sources. After a scaling group is created based on an ECS instance, the system creates a default scaling configuration that uses the pay-as-you-go billing method. For more information about scaling groups, see Overview.

Note

The default scaling configuration uses the base image of the ECS instance, instead of creating a custom image from the instance. If you want the scaling configuration to use an image that contains all the system configurations and data of the existing ECS instance, create a custom image from the ECS instance and then use the custom image to update the scaling configuration. For more information, see Update an image in a scaling configuration.

After a scaling group is created, you can manually add existing ECS instances or configure ECS instances to be automatically added to the scaling group. Only pay-as-you-go and preemptible ECS instances can be automatically created in scaling groups, whereas subscription, pay-as-you-go, and preemptible instances can be manually added to scaling groups. For more information about limits on scaling groups, see Limits.

Procedure

  1. Open the Create Scaling Group dialog box.

    1. Log on to the ECS console.

    2. In the left-side navigation pane, choose Instances & Images > Instances.

    3. In the upper-left corner of the top navigation bar, select a region.

    4. Find the ECS instance based on which you want to create a scaling group. In the Actions column, choose 1 > Deployment & Elasticity > Create Scaling Group.

  2. In the Create Scaling Group dialog box, configure parameters and click OK.

    If you create a scaling group from scratch, you must manually specify all parameters. If you create a scaling group based on an existing ECS instance, the following parameters are automatically specified:

    • Instance Configuration Source: is set to Select Existing Instance. The system extracts the configurations of your selected ECS instance to create a default scaling configuration and uses the scaling configuration to create ECS instances in the scaling group. The extracted ECS instance configurations include the instance type, base image, network type, security groups, logon password, and tags. If some of the ECS instance configurations such as the image do not meet your business requirements, you can modify the scaling configuration after the scaling group is created.

    • Network Type: is set to the network type of the selected ECS instance.

    • VPC: is set to the virtual private cloud (VPC) ID of the selected ECS instance if the instance is deployed in a VPC.

    • vSwitch: is set to the ID of the vSwitch to which the selected ECS instance is connected if the instance is deployed in a VPC.

    The following table describes the parameters that are required to create a scaling group. Accept the values that are automatically specified for parameters. For more information about how to configure a scaling group, see Manage scaling groups.

    Parameter

    Description

    Scaling Group Name

    The name of a scaling group must be 2 to 64 characters in length, and can contain letters, digits, periods (.), underscores (_), and hyphens (-). The name must start with a letter or a digit.

    Type

    The type of instances that provide computing power in the scaling group. The type of instances that Auto Scaling adds to or removes from the scaling group during a scaling activity is also based on the value of the Type parameter. Valid values:

    • ECS: ECS instances

    • ECI: elastic container instances

    Instance Configuration Source

    Auto Scaling creates instances based on the value of the Instance Configuration Source parameter. Valid values:

    • Launch Templates: A launch template contains information such as the key pair, RAM role, instance type, and network settings. A launch template does not contain passwords. The Launch Templates setting is available only if you set the Type parameter to ECS.

      If you set the Instance Configuration Source parameter to Launch Templates, you must also configure the Select Launch Template and Select Template Version parameters. To meet diverse business requirements, you can specify multiple instance types in the Extend Instance Type of Launch Template section. For information about how to specify weights for instance types, see Use performance metrics to measure Auto Scaling.

    • Select Existing Instance: You must select an existing instance. Auto Scaling extracts the basic configurations of the selected instance to create a default scaling configuration.

      If you set the Type parameter to ECS, the basic configurations that are extracted from the selected instance include the instance type, network type, security group, and base image. The instance logon password and tags are not included. The base image is the image that is used by the existing instance. The base image does not include instance data such as application data. If you want to obtain the system configurations and application data of the selected instance, create a custom image for the instance and use the custom image to replace the base image in the scaling configuration. For information about how to replace images, see Update an image in a scaling configuration.

    • Create from Scratch: You can continue to create the scaling group without the need to specify a template. You must specify a scaling configuration or launch template only after you create the scaling group. The steps that you must perform to create a scaling configuration vary based on the value of the Type parameter. For more information, see Create a scaling configuration of the ECS type and Create a scaling configuration of the Elastic Container Instance type.

    Note

    If you create a scaling group based on ECS instances in the ECS console, Auto Scaling automatically fills the instance configuration source and network type. We recommend that you do not modify the settings.

    Tag

    You can add tags to easily find and manage scaling groups. For more information, see Overview.

    Note

    The tags apply only to the scaling group. If you want to add tags to an instance in the scaling group, configure the tags in the scaling configuration or the launch template based on which the instance is created.

    Tags Propagated to Instances During Scale-out

    After you add one or more tags to the scaling group, you can continue to specify the tags that you want to add to instances during scale-outs.

    Scale-In Policy

    If you want to remove instances from the scaling group and you have multiple options, you can configure this parameter. If multiple instances meet the removal conditions after the scale-in policy takes effect, a random instance is removed. This parameter is available only if you set the Type parameter to ECS.

    The Scale-In Policy parameter contains the First Remove and Then Remove fields. Specify different values for the two fields. Valid values:

    Note

    If you set the Type parameter to ECI, Auto Scaling removes the instances that are created based on the earliest scaling configuration. Then, Auto Scaling removes the instances that are created at the earliest point in time from the results that are obtained based on the First Remove field.

    • Earliest Instance Created Using Scaling Configuration: Auto Scaling removes instances that are created based on the earliest scaling configuration or the earliest launch template. No scaling configuration or launch template is associated with instances that are manually added to the scaling group. Therefore, instances that are manually added are not removed first. If more instances need to be removed from a scaling group after Auto Scaling removes all instances with which the earliest scaling configuration or the earliest launch template is associated, Auto Scaling removes manually added instances in a random manner.

      Note

      The scaling configuration source in the Earliest Instance Created Using Scaling Configuration setting can be a scaling configuration or a launch template.

      The version of a launch template does not indicate the order in which the template is added. For example, if you specify the lt-foress V2 launch template when you create a scaling group, and then replace the template with the lt-foress V1 launch template when you modify the scaling group, Auto Scaling considers the lt-foress V2 launch template as the earliest template.

    • Earliest Created Instance: Auto Scaling removes the instances that are created at the earliest point in time.

    • Most Recent Created Instance: Auto Scaling removes the instances that are created at the most recent point in time.

    • Custom Policy: Auto Scaling removes instances from the scaling group based on a custom policy. The custom policy contains a service. service version, and function.

    If Auto Scaling removes instances based on the Earliest Instance Created Using Scaling Configuration setting, you can set the Then Remove field to one of the following values:

    • No Policy: Auto Scaling does not remove instances from the results that are obtained based on the First Remove field.

    • Earliest Created Instance: Auto Scaling removes the instances that are created at the earliest point in time from the results that are obtained based on the First Remove field.

    • Most Recent Created Instance: Auto Scaling removes the instances that are created at the most recent point in time from the results that are obtained based on the First Remove field.

    Note

    The value of the Scaling Policy parameter also affects the manner in which instances are removed from scaling groups. For information about how to remove ECS instances from scaling groups, see Combine scaling policies and scale-in policies.

    Suspend Process

    You can suspend processes before you perform specific operations. For example, you can suspend the health check process before you stop an instance. This way, if the health check fails, the instance is not removed from the scaling group. You can suspend the following processes in a scaling group:

    • Scale-out: If you suspend this type of process, Auto Scaling rejects all scale-out requests.

    • Scale-in: If you suspend this type of process, Auto Scaling rejects all scale-in requests.

    • Health Check: If you suspend this type of process, Auto Scaling suspends health checks and does not remove unhealthy instances.

    • Scheduled Task: If you suspend this type of process, Auto Scaling does not execute the scaling rules that are associated with a scheduled task when the execution time of the scheduled task arrives.

    • Event-triggered Task: If you suspend this type of process, Auto Scaling does not execute the scaling rules that are associated with an event-triggered task when the event-triggered task enters the Alert state.

    For more information, see Suspend and resume scaling group processes.

    Deletion Protection

    After you enable this feature, you cannot delete the scaling group in the Auto Scaling console or by calling API operations. This helps prevent scaling groups from being accidentally deleted.

    Instance Health Check

    After you enable this feature, Auto Scaling checks the status of instances on a regular basis. If Auto Scaling detects that an instance does not run as expected, Auto Scaling considers the instance unhealthy and removes the instance from the scaling group. For more information, see Instance lifecycles.

    Minimum Number of Instances

    If the number of instances in the scaling group is less than the value of this parameter, Auto Scaling adds instances to the scaling group until the number of instances in the scaling group reaches the minimum number.

    Maximum Number of Instances

    If the number of instances in the scaling group is greater than the value of this parameter, Auto Scaling removes instances from the scaling group until the number of instances in the scaling group does not exceed the maximum number.

    Expected Number of Instances

    If you enable the Expected Number of Instances feature for the scaling group, Auto Scaling maintains the expected number of instances in the scaling group. For more information, see Expected number of instances.

    Note

    You can enable the Expected Number of Instances feature when you create or modify a scaling group. If you want to disable the Expected Number of Instances feature, you can call the ModifyScalingGroup operation.

    Maximum Life Span of Instance (Seconds)

    The maximum life span of an instance in the scaling group. After the specified life span of the instance elapses, Auto Scaling creates a new instance to replace the instance.

    This parameter is available only if you set the Type parameter to ECS.

    Default Cooldown Time (Seconds)

    The cooldown period of the scaling group after a scaling activity is complete. During the cooldown period, Auto Scaling rejects all scaling requests that are triggered by event-triggered tasks. Scaling activities that are triggered by other types of tasks, such as scheduled tasks and manually executed tasks, are not subject to the cooldown period and can be immediately executed.

    Network type

    The following parameters are available only if you set the Network Type parameter to VPC: Scaling Policy, Instance Reclaim Mode, vSwitch, and Associate ALB and NLB Server Groups.

    Note

    If you create a scaling group based on ECS instances in the ECS console, Auto Scaling automatically fills the instance configuration source and network type. We recommend that you do not modify the settings.

    A scaling group and instances in the scaling group must belong to the same network type. For example, if a scaling group resides in a VPC, the instances in the scaling group must also reside in the VPC. If a scaling group resides in the classic network, the instances in the scaling group must also reside in the classic network.

    Important

    After you create a scaling group, you cannot change the network type of the scaling group.

    Scaling Policy

    The Scaling Policy parameter is available only if you set the Type parameter to ECS and the Network Type parameter to VPC. Valid values:

    • Priority Policy: Auto Scaling preferentially creates instances in the zone where the vSwitch that has the highest priority resides. If the scaling fails, Auto Scaling creates instances in the zone where the vSwitch that has the next highest priority resides.

      Note

      By default, if you set the Type parameter to ECI, Priority Policy is used.

    • Balanced Distribution Policy: This policy is valid only if the scaling group is associated with multiple vSwitches that are distributed across two or more zones. Auto Scaling evenly distributes instances across the zones where the vSwitches reside based on the policy. If instances are not evenly distributed across multiple zones due to insufficient resources, you can use Balanced Distribution Policy to evenly redistribute instances across the zones. For more information, see Rebalance the distribution of ECS instances.

    • Cost Optimization Policy: This policy is valid only if you specify multiple instance types in the scaling configuration. When a scale-out is triggered, Auto Scaling preferentially creates ECS instances that have the lowest-priced vCPUs. When a scale-in is triggered, Auto Scaling preferentially removes ECS instances that have the highest-priced vCPUs from the scaling group. If you specify Preemptible Instance as the billing method in the scaling configuration, Auto Scaling preferentially creates preemptible instances. If preemptible instances cannot be created due to insufficient resources, Auto Scaling creates pay-as-you-go instances.

      If you select Cost Optimization Policy, configure the following parameters based on your business requirements:

      • Minimum Pay-as-you-go Instances: the minimum number of pay-as-you-go ECS instances in the scaling group. Default value: 0. If the number of pay-as-you-go ECS instances in the scaling group is less than the value of this parameter, 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 ECS instances that are automatically created. Default value: 70%. When you calculate the percentage, the pay-as-you-go ECS instances do not include the minimum number of pay-as-you-go ECS instances that is specified by the Minimum Pay-as-you-go Instances parameter.

      • Lowest Cost Instance Types: the number of lowest-priced instance types. Default value: 1. This parameter takes effect only when multiple instance types are specified in the scaling configuration. Auto Scaling evenly creates preemptible ECS instances of the lowest-priced instance types.

      • Enable Supplemental Preemptible Instances: After you enable this feature, Auto Scaling automatically creates preemptible instances five minutes before the existing instances are reclaimed.

      • Use Pay-as-you-go Instances to Supplement Preemptible Capacity: By default, this feature is enabled. Auto Scaling creates pay-as-you-go instances to meet the requirement on the number of preemptible instances when preemptible instances cannot be created due to factors such as cost-related issues and insufficient resources.

    • Custom Combination Policy: You can create a custom scaling policy. If you want to adjust the ratio of pay-as-you-go instances to preemptible instances, balance the instance distribution between multiple zones, or select desired instance types, you can set the Scaling Policy parameter to Custom Combination Policy.

    Instance Reclaim Mode

    The Instance Reclaim Mode parameter is available only if you set the Type parameter to ECS and the Network Type parameter to VPC. Valid values:

    • Release: releases instances that are removed from the scaling group. In this case, no resources are retained. If a scale-out is triggered, Auto Scaling creates new instances and adds the instances to the scaling group.

      Note

      If you set the Type parameter to ECI, elastic container instances that are removed from the scaling group are released.

    • Economical Mode: stops instances that are removed from the scaling group in Economical Mode. In this case, you are still charged for resources that are retained. If a scale-out is triggered, Auto Scaling preferentially adds the instances that are stopped in Economical Mode to the scaling group. If the number of instances that are in Economical Mode does not meet the scale-out requirement, Auto Scaling creates and adds new instances. The Economical Mode setting helps improve the efficiency of scaling. For more information, see Use the Economical Mode feature to scale instances faster.

      Important
      • Data that is stored on instances may be lost when the instances are reclaimed. To prevent data loss, do not store application data or logs on instances.

      • In the following scenarios, instances that are stopped in Economical Mode may be released:

        • If you manually modify the value of the Maximum Number of Instances parameter for the scaling group and the number of instances in all status in the scaling group is less than the new value of the Maximum Number of Instances parameter, Auto Scaling preferentially releases instances that are stopped in Economical Mode.

        • If your Alibaba Cloud account has overdue payments or insufficient resources, instances that are stopped in Economical Mode may fail to be added to the scaling group during a scale-out. In this case, Auto Scaling may release the failed instances.

      • You can put only pay-as-you-go instances into Economical Mode. For more information about the Economical Mode feature, see the "Prerequisites", "Application resources", and "Trigger effects" sections in the Economical mode topic.

    • Forcibly Release: forcibly releases ECS instances that are in the Running state during scale-ins. Forcible release is equivalent to power outage. If you allow the system to forcibly release an instance, ephemeral data on the instance will be cleared beyond recovery. Exercise caution when you select this option.

    VPC

    Select an existing VPC.

    Note

    If you create a scaling group based on ECS instances in the ECS console, Auto Scaling automatically fills the instance configuration source and network type. We recommend that you do not modify the settings.

    vSwitch

    After you select a VPC, you must select one or more vSwitches. Each vSwitch resides in a single zone. To deploy instances across multiple zones, you can specify multiple vSwitches. We recommend that you select multiple zones to increase the success rate of scale-outs.

    Note

    If you create a scaling group based on ECS instances in the ECS console, Auto Scaling automatically fills the instance configuration source and network type. We recommend that you do not modify the settings.

    When you create a scaling group, you must specify VPCs and vSwitches. If the launch template that is used by the scaling group also has VPCs and vSwitches, the VPCs and vSwitches of the scaling group override the VPCs and vSwitches of the launch template during scale-outs. In this case, Auto Scaling creates ECS instances in the zones where the vSwitches of the scaling group reside, instead of the zones where the vSwitches of the launch template that is used by the scaling group reside. Example:

    • Set the VPC parameter to VPC-A.

    • Set the vSwitch parameter to vSwitch-A.

    • Set the Instance Configuration Source parameter to Launch Templates.

      The selected launch template uses VPC-B as the value of the VPC parameter and vSwitch-B as the value of the vSwitch parameter.

    In this example, Auto Scaling creates ECS instances of the VPC-A network type in the zone where vSwitch-A resides during a scale-out.

    Add Existing Instance

    The Add Existing Instance parameter is available only if you set the Type parameter to ECS and set the Instance Configuration Source parameter to Launch Template or Select Existing Instance.

    If you configure the Expected Number of Instances and Add Existing Instance parameters at the same time, the value of the Expected Number of Instances parameter automatically increases. For example, if you set the Expected Number of Instances parameter to 1 and set the Add Existing Instance parameter to 2 when you create a scaling group, the value of the Expected Number of Instances parameter automatically increases from 1 to 3.

    If you want to use the scaling group to manage the instance lifecycles, you can select Enable the scaling group to manage the instance lifecycle.

    • If you enable this feature, Auto Scaling may remove instances that are considered unhealthy. Auto Scaling may also release the instances that you manually remove from the scaling group.

    • If you do not enable this feature, Auto Scaling does not release instances that are removed from the scaling group.

    Note

    You can add subscription instances to the scaling group, but you cannot enable the scaling group to manage the lifecycles of the subscription instances.

    Associate CLB Instance

    After you associate a CLB instance with a scaling group, Auto Scaling adds the instances in the scaling group to the backend server groups of the CLB instance as backend servers. Then, the CLB instance forwards requests to the backend servers.

    You can specify the following types of server groups to which you can add instances. Valid values:

    • Default server group: the group of instances that are used to receive requests. If you do not specify a vServer group or a primary/secondary server group for a listener, requests are forwarded to the instances in the default server group.

    • vServer group: If you want to forward requests to backend servers that are not in the default server group or configure domain name- or URL-based routing methods, you can use vServer groups.

    If you specify the default server group and multiple vServer groups at the same time, the instances are added to all specified server groups.

    Note

    You can associate only a limited number of CLB instances and vServer groups with a scaling group. To view the quota or request a quota increase, go to Quota Center.

    Associate ALB and NLB Server Groups

    The Associate ALB and NLB Server Groups parameter is available only if you set the Network Type parameter to VPC. After you associate an ALB or NLB server group with a scaling group, Auto Scaling adds instances in the scaling group to the ALB or NLB server group as backend servers. Then, the ALB or NLB instance forwards requests to the backend servers. You must specify the port number and weight for each backend server. By default, the weight of a backend server is 50. If you increase the weight of a server, the number of requests that are forwarded to the server also increases. If you set the weight of a backend server to 0, no requests are forwarded to the server.

    If you associate multiple ALB or NLB server groups with the same scaling group, Auto Scaling adds instances in the scaling group to all associated ALB or NLB server groups at the same time.

    Note

    You can associate only a limited number of ALB or NLB server groups with a scaling group. To view the quota or request a quota increase, go to Quota Center.

    Associate ApsaraDB RDS Instance

    The Associate ApsaraDB RDS Instance parameter is available only if you set the Type parameter to ECS. After you associate an ApsaraDB RDS instance with a scaling group, Auto Scaling adds the private IP addresses of the ECS instances in the scaling group to the IP address whitelist of the ApsaraDB RDS instance. This way, the ECS instances in the scaling group can communicate with the ApsaraDB RDS instance over an internal network.

    Note

    You can associate only a limited number of ApsaraDB RDS instances with a scaling group. To view the quota or request a quota increase, go to Quota Center.

    Create Regular Rule

    When a scaling activity succeeds, fails, or is rejected, Auto Scaling notifies you by text messages, internal messages, or emails based on the rule. For more information, see Create a regular notification rule.

    Resource Group

    You can add scaling groups to resource groups. Then you can manage scaling group resources by resource group. This facilitates resource isolation and permission control. For more information, see Use resource groups to manage scaling groups in a fine-grained manner.

    Synchronize Alert Rule to CloudMonitor

    You can enable or disable this feature only when you create a scaling group. After you enable this feature, Alibaba Cloud creates and associates a CloudMonitor application group with the scaling group. The alert rules of the scaling group are displayed in the CloudMonitor console in a synchronous manner.

  3. In the Create Scaling Group dialog box, click OK.

  4. On the Scaling Groups page, find the scaling group that you created. In the Actions column, choose more > Enable.

    After the scaling group is enabled, Auto Scaling maintains a collection of ECS instances based on the settings of the scaling group, such as the instance configuration source and minimum number of instances. For example, if the minimum number of instances is set to a non-zero value, Auto Scaling creates a number of ECS instances in the scaling group to ensure that the actual number of instances in the scaling group is greater than or equal to the minimum number.

Related operations

You can manually add, remove, or delete ECS instances for the scaling group. Alternatively, you can configure scheduled tasks or event-triggered tasks to automatically scale the scaling group. For more information, see the following topics: