All Products
Search
Document Center

Auto Scaling:Create a scaling configuration of the Elastic Container Instance type

Last Updated:Oct 21, 2024

This topic describes how to create a scaling configuration of the Elastic Container Instance type. If a scale-out event is triggered, Auto Scaling uses the scaling configuration as the template to create elastic container instances. You can create a scaling configuration by using one of the following methods: Create by Form and Create by YAML File.

Prerequisites

  • A scaling group of the Elastic Container Instance type is created. For more information, see Manage scaling groups.

  • A security group is created. If the network type of the scaling group is virtual private network (VPC), make sure that the security group and the scaling group reside in the same VPC. For more information, see Create a security group.

Procedure

Alibaba Cloud provides multiple methods to create a scaling configuration of the Elastic Container Instance type. You can select one of the following methods based on your business requirements:

  • Create by Form

    You can create a scaling configuration of the Elastic Container Instance type on the Create by Form tab of the Auto Scaling console. For more information, see Method 1: Create a scaling configuration on the Create by Form tab.

  • Create by YAML File

    You can also use a Kubernetes YAML file in which you declare the configurations that you want to use to create and manage a scaling configuration. Auto Scaling allows you to compile a Kubernetes YAML file to create and manage a scaling configuration. Auto Scaling also allows you to use Alibaba Cloud Command Line Interface (CLI) to create and manage a scaling configuration. For more information, see Method 2: Create a scaling configuration on the Create by YAML File tab.

Method 1: Create a scaling configuration on the Create by Form tab

  1. Go to the Create Scaling Configuration page.

    1. Log on to the Auto Scaling console.

    2. In the left-side navigation pane, click Scaling Groups.

    3. In the top navigation bar, select a region.

    4. On the Scaling Groups page, find the scaling group that you want to manage and click Details in the Actions column.

    5. Click the Instance Configuration Sources tab and then the Scaling Configurations tab. Then, click Create Scaling Configuration to go to the Create Scaling Configuration page.

  2. On the Create Scaling Configuration page, click the Create by Form tab and configure the parameters as prompted to create a scaling configuration. Click Next: Other Settings.

    For information about parameter details, see Basic Settings step.

  3. (Optional) Configure parameters in the Other Settings (Optional) step as prompted.

    For information about parameter details, see Other Settings (Optional) step.

  4. Click Confirm Configuration. In the Confirm step, check the scaling configuration and click Create Order.

  5. (Optional) Enable the scaling configuration.

    After you click Create Order, click Enable in the Success message to enable the scaling configuration.

    Note

    If you do not want to enable a scaling configuration immediately after you create the scaling configuration, you can enable it subsequently on the Scaling Configurations tab based on your business requirements. For more information, see Apply or enable scaling configurations.

Method 2: Create a scaling configuration on the Create by YAML File tab

Use the Auto Scaling console

  1. Go to the Create Scaling Configuration page.

    1. Log on to the Auto Scaling console.

    2. In the left-side navigation pane, click Scaling Groups.

    3. In the top navigation bar, select a region.

    4. On the Scaling Groups page, find the scaling group that you want to manage and click Details in the Actions column.

    5. Click the Instance Configuration Sources tab and then the Scaling Configurations tab. Then, click Create Scaling Configuration to go to the Create Scaling Configuration page.

  2. On the Create Scaling Configuration page, click the Create by YAML File tab. Compile a YAML file.

    Sample code:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-demo
      annotations:
        # The name of the scaling configuration.
        k8s.aliyun.com/ess-eci-scaling-configuration-name: create-ess-config-by-yaml
    spec:
      # The expected number of instances in the scaling group.
      template:
        metadata:
          labels:
              app: nginx-demo
          annotations:
            # The ID of the vSwitch. You can specify up to eight vSwitches in the same VPC. Separate multiple vSwitches with commas (,).
            k8s.aliyun.com/eci-vswitch: vsw-bp******1,vsw-bp******2,vsw-bp******3,vsw-bp******4
            # The ID of the security group. You can specify up to five security groups in the same VPC. Separate multiple security groups with commas (,).
            k8s.aliyun.com/eci-security-group: sg-bp******1,sg-bp******2
            # Specifies whether to automatically create and bind elastic IP addresses (EIPs).
            k8s.aliyun.com/eci-with-eip: 'true'
            # The instance type of elastic container instances.
            k8s.aliyun.com/eci-use-specs: 1.0-2.0Gi
            # The EIP bandwidth.
            k8s.aliyun.com/eip-bandwidth: '5'
        spec:
          containers:
            - name: nginx
              # The image.
              image: nginx:latest
              ports:
                - containerPort: 80
                  name: http
                - containerPort: 443
                  name: https
              resources:
                requests:
                  memory: 0.05Gi
                  cpu: 50m
                limits:
                  memory: 2Gi
                  cpu: '2'

    The following table describes the parameters used in the preceding YAML file. For information about all supported parameters, see YAML fields.

    Parameters

    Parameter

    Description

    Example

    k8s.aliyun.com/ess-eci-scaling-configuration-name

    The name of the scaling configuration.

    create-ess-config-by-yaml

    k8s.aliyun.com/eci-vswitch

    The ID of the vSwitch. You can specify up to eight vSwitches in the same VPC. Separate multiple vSwitches with commas (,).

    Important

    If you do not specify the VPC and vSwitches, Auto Scaling creates a default VPC and vSwitch. For more information, see Default VPCs and default vSwitches.

    vsw-bp******1,vsw-bp******2,vsw-bp******3

    k8s.aliyun.com/eci-security-group: sg-bp******

    The ID of the security group. You can specify up to five security groups in the same VPC.

    Important

    The security group and vSwitches must be in the same VPC.

    sg-bp******1,sg-bp******2

    k8s.aliyun.com/eci-with-eip

    Specifies whether to automatically allocate EIPs. If you set this parameter to true, EIPs are automatically assigned to elastic container instances.

    true

    k8s.aliyun.com/eci-use-specs

    The instance type of elastic container instances. An instance type can be a combination of vCPUs and memory size or an Elastic Compute Service (ECS) instance type. You can specify multiple instance types.

    1.0-1.0Gi

    k8s.aliyun.com/eip-bandwidth

    The EIP bandwidth. Unit: Mbit/s. Default value: 5.

    5

  3. Click Create. In the Confirm Information message, confirm the configurations and click Confirm.

  4. (Optional) Enable the scaling configuration.

    After you click Confirm, click OK in the Enable Scaling Configuration message to enable the scaling configuration.

    Note

    If you do not want to enable a scaling configuration immediately after you create the scaling configuration, you can enable it subsequently on the Scaling Configurations tab based on your business requirements. For more information, see Apply or enable scaling configurations.

Use Alibaba Cloud CLI

You can use Alibaba Cloud CLI to manage scaling configurations. The following section describes how to use Alibaba Cloud CLI to execute a YAML file and create a scaling configuration of the Elastic Container Instance type. The Nginx:latest image is used as an example.

Important

Before you proceed to the following steps, make sure that Alibaba Cloud CLI is installed and the required credentials and environment variables are configured. For more information, see What is Alibaba Cloud CLI?.

  1. Create a file named create-ess-config.yaml.

    Sample code:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-demo
      annotations:
        # The name of the scaling configuration.
        k8s.aliyun.com/ess-eci-scaling-configuration-name: create-ess-config-by-yaml
    spec:
      # The expected number of instances in the scaling group.
      template:
        metadata:
          labels:
              app: nginx-demo
          annotations:
            # The ID of the vSwitch. You can specify up to eight vSwitches in the same VPC. Separate multiple vSwitches with commas (,).
            k8s.aliyun.com/eci-vswitch: vsw-bp******1,vsw-bp******2,vsw-bp******3,vsw-bp******4
            # The ID of the security group. You can specify up to five security groups in the same VPC. Separate multiple security groups with commas (,).
            k8s.aliyun.com/eci-security-group: sg-bp******1,sg-bp******2
            # Specifies whether to automatically create and bind elastic IP addresses (EIPs).
            k8s.aliyun.com/eci-with-eip: 'true'
            # The instance type of elastic container instances.
            k8s.aliyun.com/eci-use-specs: 1.0-2.0Gi
            # The EIP bandwidth.
            k8s.aliyun.com/eip-bandwidth: '5'
        spec:
          containers:
            - name: nginx
              # The image.
              image: nginx:latest
              ports:
                - containerPort: 80
                  name: http
                - containerPort: 443
                  name: https
              resources:
                requests:
                  memory: 0.05Gi
                  cpu: 50m
                limits:
                  memory: 2Gi
                  cpu: '2'

    The following table describes the parameters used in the preceding YAML file. For information about all supported parameters, see YAML fields.

    Parameters

    Parameter

    Description

    Example

    k8s.aliyun.com/ess-eci-scaling-configuration-name

    The name of the scaling configuration.

    create-ess-config-by-yaml

    k8s.aliyun.com/eci-vswitch

    The ID of the vSwitch. You can specify up to eight vSwitches in the same VPC. Separate multiple vSwitches with commas (,).

    Important

    If you do not specify the VPC and vSwitches, Auto Scaling creates a default VPC and vSwitch. For more information, see Default VPCs and default vSwitches.

    vsw-bp******1,vsw-bp******2,vsw-bp******3

    k8s.aliyun.com/eci-security-group: sg-bp******

    The ID of the security group. You can specify up to five security groups in the same VPC.

    Important

    The security group and vSwitches must be in the same VPC.

    sg-bp******1,sg-bp******2

    k8s.aliyun.com/eci-with-eip

    Specifies whether to automatically allocate EIPs. If you set this parameter to true, EIPs are automatically assigned to elastic container instances.

    true

    k8s.aliyun.com/eci-use-specs

    The instance type of elastic container instances. An instance type can be a combination of vCPUs and memory size or an Elastic Compute Service (ECS) instance type. You can specify multiple instance types.

    1.0-1.0Gi

    k8s.aliyun.com/eip-bandwidth

    The EIP bandwidth. Unit: Mbit/s. Default value: 5.

    5

  2. Run the following command in the directory of the create-ess-config.yaml file to create a scaling configuration:

    Important

    Modify the following parameters in the command based on your business requirements:

    • --RegionId: the region ID of your scaling group. In this example, cn-hangzhou is used.

    • --ScalingGroupId: the ID of your scaling group. In this example, asg-bp******v is used.

    aliyun ess ApplyEciScalingConfiguration --RegionId cn-hangzhou --ScalingGroupId asg-bp******v --Content "$(cat create-ess-config.yaml)" --version 2022-02-22 --method POST --force

Parameters

Basic Settings step

Parameter

Description

References

Billing Method

The billing method of elastic container instances created from the scaling configuration. Valid values:

  • Pay-as-you-go: Auto Scaling allocates and releases resources on demand. You are charged only for the resources that you use. You do not need to purchase resources in advance.

  • Preemptible Instance: The market price of a preemptible instance varies based on the supply and the demand of the instance type. Preemptible instances can be more cost-effective than pay-as-you-go instances. However, preemptible instances may be automatically reclaimed. You can use preemptible instances to reduce costs in specific business scenarios.

Billing overview

Configuration Information

The region, VPC, and vSwitches of elastic container instances created from the scaling configuration. The configuration information is automatically populated. Elastic container instances and the scaling group to which the instances belong must be in the same region and VPC and use the same vSwitches.

N/A

Security Group

The security group of elastic container instances created from the scaling configuration.

Create a security group

Container Group Configurations

The mode in which you specify instance types in the scaling configuration. Value values:

  • Basic Mode

    In this mode, you can directly specify resources, such as the number of vCPUs and memory size, and whether to enable features, such as image cache and cost optimization, for creating elastic container instances.

  • Specify Instance Type

    In this mode, you can specify ECS instance types to create elastic container instances. If your business has specific requirements, such as a specific GPU model, you can use this mode. For more information, see Specify ECS instance types to create an elastic container instance.

If you want to add storage volumes to elastic container instances, you can configure the parameters in the Storage section of the Advanced Settings folding panel. For more information, see Overview of volumes.

Container Configurations

In this section, you can add containers, select a container image and image tag, specify an image pulling policy, and compile container startup commands.

You can also specify the number of vCPUs and memory size, configure environment variables, and add storage space for each container in the Advanced Settings folding panel.

Other Settings (Optional) step

Parameter

Description

References

EIP

If you want to enable Internet access for elastic container instances, click Auto Create and configure the Maximum Bandwidth parameter.

Enable Internet access for elastic container instances

Credential

If the image that you want to specify for containers is from a private image repository, you must configure this parameter to enable Auto Scaling to pull the image from the private image repository.

N/A

RAM Role

If the elastic container instances in your scaling group need to access other cloud resources, you must assign the required permissions to a Resource Access Management (RAM) role and then assign the RAM role to the elastic container instances.

Assign a RAM role to a pod

Tag

If you add tags to the scaling configuration, all elastic container instances created from the scaling configuration are bound to the tags. You can use tags to manage elastic container instances in a finer-grained manner.

Use tags to manage elastic container instances

Resource Group

If you configure a resource group, all elastic container instances created from the scaling configuration belong to the resource group. You can manage the permissions of RAM users by resource group.

Use resource groups to control the permissions of a RAM user

Scaling Configuration Name

The name of the scaling configuration. If you do not configure this parameter, the scaling configuration ID is used.

N/A

References