All Products
Search
Document Center

Auto Scaling:ApplyScalingGroup

Last Updated:Jun 25, 2025

Quickly creates and manages a scaling group of the Elastic Container Instance type by using a configuration file.

Usage notes

The ApplyScalingGroup operation supports the use of Kubernetes Deployments to define resources, which facilitates scaling group creation. The ApplyScalingGroup operation also supports the use of annotations in Kubernetes YAML configuration files to configure elastic container instances. For more information, see the "List of supported annotations" section in this topic.

In a YAML file, you can define a triplet consisting of namespace, kind, name to map to the name of a scaling group. A triplet can map to a scaling group within a region. Example:

If you define a triplet that uses the default namespace in the nginx YAML file of the Deployment kind in a region, the name of the mapped scaling group in the same region is k8s_default_Deployment_nginx.

When you manage a scaling group by using a YAML file, the following logic must be followed:

  • If the YAML file maps to an existing scaling group, the scaling group is updated based on the YAML file.

  • If the YAML file maps to an inexistent scaling group, a scaling group is created based on the YAML file.

Precautions

  • If you do not specify annotations for a virtual private cloud (VPC), vSwitch, or security group in the YAML file, the system automatically creates a default VPC and a default vSwitch in the VPC. The system also automatically creates a default security group named ess-default-sg. By default, the ess-default-sg security group allows traffic over the TCP-based ports 22 and 3389 and uses Internet Control Message Protocol (ICMP). If you want to enable other ports or protocols, you can modify the security group settings.

  • If you use a public image, you must configure Internet access. We recommend that you specify k8s.aliyun.com/eci-with-eip pod annotation in your YAML file to enable the Elastic IP Address (EIP) feature.

  • After you apply your YAML file by calling the ApplyScalingGroup operation, the scaling group and scaling configuration take effect immediately. If you set the replicas parameter to a value greater than 0, resources are automatically created.

List of supported annotations

For more information about annotations, see ECI Pod Annotation.

Annotation

Example

Description

k8s.aliyun.com/ess-scaling-group-min-size

1

The minimum size of the scaling group that you want to create. Default value: 0.

k8s.aliyun.com/ess-scaling-group-max-size

20

The maximum size of the scaling group that you want to create. Default value: max(replicas, 30).

k8s.aliyun.com/eci-ntp-server

100.100.*.*

The IP address of the Network Time Protocol (NTP) server.

k8s.aliyun.com/eci-use-specs

2-4Gi

The specifications of 2 vCPUs and 4 GiB memory. For more information, see Create a pod by specifying multiple specifications.

k8s.aliyun.com/eci-vswitch

vsw-bp1xpiowfm5vo8o3c****

The vSwitch IDs. You can specify multiple vSwitch IDs to ensure that pods can be created in zones in which sufficient resources exist.

k8s.aliyun.com/eci-security-group

sg-bp1dktddjsg5nktv****

The ID of the security group. Requirements: You can specify one or more security groups. You can specify up to five security groups for each scaling group. If you specify multiple security groups, the security groups must belong to the same VPC and be of the same type.

k8s.aliyun.com/eci-sls-enable

"false"

Specifies whether to collect logs for the pod. If you do not want to collect logs for the pod when you use Simple Log Service CRDs (custom resource definitions) to collect logs, you can set the annotation to false to disable the log collection feature. This prevents waste of resources when the system automatically creates Logtail.

k8s.aliyun.com/eci-spot-strategy

SpotAsPriceGo

The bidding policy for the spot instance. You can configure this annotation based on your business requirements.

  • SpotWithPriceLimit: The instance is created as a spot instance for which you specify the maximum hourly price In this case, you must also configure k8s.aliyun.com/eci-spot-price-limit.

  • SpotAsPriceGo: The instance is a spot instance for which the system automatically bids based on the current market price.

k8s.aliyun.com/eci-spot-price-limit

"0.5"

The maximum hourly price of the spot instance. This value can be accurate to three decimal places. If

k8s.aliyun.com/eci-spot-strategy

is set to

SpotWithPriceLimit,

this annotation takes effect.

k8s.aliyun.com/eci-with-eip

"true"

Specifies whether to automatically create an EIP when you create an elastic container instance and associate the EIP with the instance.

k8s.aliyun.com/eci-data-cache-bucket

default

The bucket that is used to store the DataCache. You must configure this annotation when you use DataCaches to create pods.

k8s.aliyun.com/eci-data-cache-pl

PL1

The performance level (PL) of the disk that is created based on the DataCache. By default, a PL1 enhanced SSD (ESSD) is used.

k8s.aliyun.com/eci-data-cache-provisionedIops

"40000"

The read/write IOPS that is provisioned for the ESSD AutoPL disk. Valid values: 0 to min{50000, 1000 x Capacity - Baseline IOPS}, where Baseline IOPS = min{1800 + 50 x Capacity, 50000}. For more information, see ESSD AutoPL disks. If you add this annotation, the disk that is created based on the DataCache is an ESSD AutoPL disk.

k8s.aliyun.com/eci-data-cache-burstingEnabled

"true"

Specifies whether to enable the performance burst feature for the ESSD AutoPL disk. For more information, see ESSD AutoPL disks. If you add this annotation, the disk that is created based on the DataCache is an ESSD AutoPL disk.

k8s.aliyun.com/eci-custom-tags

"env:test,name:alice"

The tags. You can bind up to three tags. Separate the tag key and tag value with colons (:). Separate multiple tags with commas (,).

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter

Type

Required

Example

Description

Action

String

Yes

ApplyScalingGroup

The operation that you want to perform. Set the value to ApplyScalingGroup.

ClientToken

String

No

123e4567-e89b-12d3-a456-42665544****

The client token that you want to use to ensure the idempotence of the request. You can use the client to generate the token, but you must make sure that the token is unique among different requests. The token can contain only ASCII characters and cannot exceed 64 characters in length. For more information, see Ensure impotence.

Content

String

Yes

apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx annotations: k8s.aliyun.com/eip-bandwidth: 10 k8s.aliyun.com/eci-with-eip: true spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80

The content of the configuration file.

RegionId

String

No

cn-hangzhou

The region ID.

Format

String

No

YAML

Optional. The format of the configuration file. Default value: YAML. Valid value: YAML.

Response parameters

Parameter

Type

Example

Description

RequestId

String

CC107349-57B7-4405-B1BF-9BF5AF7F****

The request ID.

ScalingGroupId

String

asg-bp1igpak5ft1flyp****

The ID of the enabled scaling group.

Examples

Sample requests

http(s)://ess.aliyuncs.com/?Action=ApplyScalingGroup
&ClientToken=123e4567-e89b-12d3-a456-42665544****
&Content=apiVersion: apps/v1 kind: Deployment metadata:   name: nginx-deployment   labels:     app: nginx   spec:     replicas: 3     selector:        matchLabels:         app: nginx     template:       metadata:         labels:           app: nginx         annotations:           k8s.aliyun.com/eip-bandwidth: 10           k8s.aliyun.com/eci-with-eip: true         spec:           containers:           - name: nginx             image: nginx:1.14.2             ports:             - containerPort: 80
&RegionId=cn-hangzhou
&Format=YAML
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<ApplyScalingGroupResponse>
    <RequestId>CC107349-57B7-4405-B1BF-9BF5AF7F****</RequestId>
    <ScalingGroupId>asg-bp1igpak5ft1flyp****</ScalingGroupId>
</ApplyScalingGroupResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "CC107349-57B7-4405-B1BF-9BF5AF7F****",
  "ScalingGroupId" : "asg-bp1igpak5ft1flyp****"
}

Error codes

For a list of error codes, see Service error codes.