Create an ECI scaling group

Updated at:
Copy as MD

A scaling group is a collection of instances that share the same application scenarios and instance type (ECS or elastic container instance). When you run container applications on elastic container instances, Auto Scaling can scale the instances based on workload. This maintains service performance and reduces usage costs.

Procedure

Alibaba Cloud provides several methods for creating scaling groups. Review the following options to choose the method that best suits your scenario.

Method 1: Create scaling group from an existing instance

Follow these steps to create an ECI scaling group from the configuration of an existing elastic container instance.

  1. Go to the Create page.

    1. Log on to the Auto Scaling console.

    2. In the top navigation bar, select the region where Auto Scaling is activated.

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

    4. On the Scaling Groups page, click Create to go to the Create page.

  2. Click the Create by Form tab and configure the parameters for the scaling group as prompted.

    The following table describes the required parameters for this method. For a complete list of all parameters, see Parameter descriptions.

    Required parameters

    Parameter

    Description

    Scaling Group Name

    Enter a name for the scaling group as prompted.

    Type

    Select the type of instances in the scaling group. Select ECI.

    Instance Configuration Source

    Select Select Existing Instance. Auto Scaling creates new instances based on the configuration of the selected instance.

    Minimum Number of Instances

    The minimum number of instances required in the scaling group. If the instance count drops below this value, Auto Scaling adds instances to meet the minimum.

    Maximum Number of Instances

    The maximum number of instances allowed in the scaling group. If the instance count exceeds this value, Auto Scaling removes instances to meet the maximum.

    Default Cooldown Time

    The default cooldown time, in seconds, after a scaling activity is complete. You can use the default value of 300. For more information, see Cooldown time.

    VPC

    All instances in your scaling group are created in this VPC. When you create a scaling group based on an existing elastic container instance, the VPC is automatically configured based on the selected instance. You can also modify this configuration.

    Warning

    The VPC cannot be changed after the scaling group is created.

    vSwitch

    After you select a VPC, you can select a vSwitch that belongs to the VPC. All instances in your scaling group are created in the specified vSwitch.

    Important

    We recommend that you select vSwitches in multiple availability zones. If you select a vSwitch in a single availability zone, instance creation may fail if inventory is insufficient.

  3. Click Create to create the scaling group.

Note
  • If you create a scaling group based on an existing elastic container instance, Auto Scaling automatically creates a scaling configuration for the scaling group. To manage the scaling configuration, see Manage scaling configurations.

  • To activate the scaling group immediately, enable it. For more information, see Enable or disable a scaling group.

Method 2: Create from scratch

If you want to configure the Instance Configuration Source for the scaling group later, follow these steps.

  1. Go to the Create page.

    1. Log on to the Auto Scaling console.

    2. In the top navigation bar, select the region where Auto Scaling is activated.

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

    4. On the Scaling Groups page, click Create to go to the Create page.

  2. Click the Create by Form tab and configure the parameters for the scaling group as prompted.

    The following table describes the required parameters to quickly create an ECI scaling group from scratch. For more information about all parameters, see Parameter descriptions.

    Required parameters

    Parameter

    Description

    Scaling Group Name

    Enter a name for the scaling group as prompted.

    Type

    Select the type of instances in the scaling group. Select ECI.

    Note

    This topic describes how to create an ECI scaling group. To create an ECS scaling group, see Create an ECS scaling group.

    Instance Configuration Source

    Select Create from Scratch. You can create the scaling group first and then configure the Instance Configuration Source. For more information, see Overview of instance configuration sources.

    Minimum Number of Instances

    The minimum number of instances required in the scaling group. If the instance count drops below this value, Auto Scaling adds instances to meet the minimum.

    Maximum Number of Instances

    The maximum number of instances allowed in the scaling group. If the instance count exceeds this value, Auto Scaling removes instances to meet the maximum.

    Default Cooldown Time

    The default cooldown time, in seconds, after a scaling activity is complete. You can use the default value of 300. For more information, see Cooldown time.

    VPC

    All instances in your scaling group are created in the VPC that you select.

    Warning

    The VPC cannot be changed after the scaling group is created.

    vSwitch

    After you select a VPC, you can select a vSwitch that belongs to the VPC. All instances in your scaling group are created in the specified vSwitch.

    Important

    We recommend that you select vSwitches in multiple availability zones. If you select a vSwitch in a single availability zone, instance creation may fail if inventory is insufficient.

  3. Click Create to create the scaling group.

Note

After you create the scaling group, you can follow the on-screen instructions to go to the scaling configuration creation page. You can also create a scaling configuration for the scaling group later. For more information, see Create a scaling configuration for ECI instances.

Method 3: Create by using a YAML file

To create a scaling group using a Kubernetes-style YAML definition, follow these steps.

Console

This section uses an nginx:latest image as an example to describe how to create an ECI scaling group from a YAML file in the Auto Scaling console.

  1. Go to the Create page.

    1. Log on to the Auto Scaling console.

    2. In the top navigation bar, select the region where Auto Scaling is activated.

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

    4. On the Scaling Groups page, click Create to go to the Create page.

  2. Click the Create by YAML File tab and compose the YAML file.

    You can use the following YAML file as a reference.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-demo
      annotations:
        # Scaling group name
        k8s.aliyun.com/ess-scaling-group-name: use-yaml-create-scaling-group
        # Minimum number of instances in the scaling group
        k8s.aliyun.com/ess-scaling-group-min-size: '0'
        # Maximum number of instances in the scaling group
        k8s.aliyun.com/ess-scaling-group-max-size: '5'
    spec:
      selector:
        matchLabels:
          app: nginx-demo
      # Desired number of instances in the scaling group
      replicas: 1
      template:
        metadata:
          labels:
              app: nginx-demo
          annotations:
            # Whether to automatically create and associate an EIP
            k8s.aliyun.com/eci-with-eip: 'true'
            # vSwitch IDs. You can specify up to 8 vSwitches in the same VPC. Separate multiple vSwitch IDs with commas (,).
            k8s.aliyun.com/eci-vswitch: vsw-bp******1,vsw-bp******2,vsw-bp******3,vsw-bp******4
            # Security group IDs. You can specify up to 5 security groups in the same VPC. Separate multiple security group IDs with commas (,).
            k8s.aliyun.com/eci-security-group: sg-bp******1,sg-bp******2
        spec:
          containers:
            - name: nginx
              # Image
              image: nginx:latest
              ports:
                - containerPort: 80
                  name: http
                - containerPort: 443
                  name: https
              resources:
                requests:
                  memory: 0.05Gi
                  cpu: 50m
                limits:
                  memory: 1Gi
                  cpu: '1'
    

    The following table describes the parameters in the sample YAML file. For more information about supported parameters, see YAML configuration parameters.

    Sample YAML parameters

    Parameter

    Description

    Example

    k8s.aliyun.com/ess-scaling-group-name

    The name of the scaling group.

    use-yaml-create-scaling-group

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

    The minimum number of instances in the scaling group.

    0

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

    The maximum number of instances in the scaling group.

    5

    k8s.aliyun.com/eci-with-eip

    Specifies whether to automatically assign an EIP. Valid values: true and false. true indicates that an EIP is automatically assigned.

    true

    k8s.aliyun.com/eci-vswitch

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

    Important

    If you do not specify a VPC and vSwitch, ESS uses or creates a default VPC and vSwitch. For more information, see Default VPC and vSwitch.

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

    k8s.aliyun.com/eci-security-group

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

    Important

    The security group must be in the same VPC as the vSwitch.

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

  3. Click Create to create the scaling group.

CLI

You can use Alibaba Cloud CLI to manage scaling groups from the command line. This section uses an nginx:latest image as an example to describe how to create an ECI scaling group from a YAML file by using Alibaba Cloud CLI.

Important

Before you begin, make sure that you have installed Alibaba Cloud CLI and configured your credentials and environment variables for it. For more information, see What is Alibaba Cloud CLI?.

  1. Create a file named use-yaml-create-scaling-group.yaml with the following content.

    You can use the following YAML file as a reference.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-demo
      annotations:
        # Scaling group name
        k8s.aliyun.com/ess-scaling-group-name: use-yaml-create-scaling-group
        # Minimum number of instances in the scaling group
        k8s.aliyun.com/ess-scaling-group-min-size: '0'
        # Maximum number of instances in the scaling group
        k8s.aliyun.com/ess-scaling-group-max-size: '5'
    spec:
      selector:
        matchLabels:
          app: nginx-demo
      # Desired number of instances in the scaling group
      replicas: 1
      template:
        metadata:
          labels:
              app: nginx-demo
          annotations:
            # Whether to automatically create and associate an EIP
            k8s.aliyun.com/eci-with-eip: 'true'
            # vSwitch IDs. You can specify up to 8 vSwitches in the same VPC. Separate multiple vSwitch IDs with commas (,).
            k8s.aliyun.com/eci-vswitch: vsw-bp******1,vsw-bp******2,vsw-bp******3,vsw-bp******4
            # Security group IDs. You can specify up to 5 security groups in the same VPC. Separate multiple security group IDs with commas (,).
            k8s.aliyun.com/eci-security-group: sg-bp******1,sg-bp******2
        spec:
          containers:
            - name: nginx
              # Image
              image: nginx:latest
              ports:
                - containerPort: 80
                  name: http
                - containerPort: 443
                  name: https
              resources:
                requests:
                  memory: 0.05Gi
                  cpu: 50m
                limits:
                  memory: 1Gi
                  cpu: '1'
    

    The following table describes the parameters in the sample YAML file. For more information about supported parameters, see YAML configuration parameters.

    Sample YAML parameters

    Parameter

    Description

    Example

    k8s.aliyun.com/ess-scaling-group-name

    The name of the scaling group.

    use-yaml-create-scaling-group

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

    The minimum number of instances in the scaling group.

    0

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

    The maximum number of instances in the scaling group.

    5

    k8s.aliyun.com/eci-with-eip

    Specifies whether to automatically assign an EIP. Valid values: true and false. true indicates that an EIP is automatically assigned.

    true

    k8s.aliyun.com/eci-vswitch

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

    Important

    If you do not specify a VPC and vSwitch, ESS uses or creates a default VPC and vSwitch. For more information, see Default VPC and vSwitch.

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

    k8s.aliyun.com/eci-security-group

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

    Important

    The security group must be in the same VPC as the vSwitch.

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

  2. In the same directory as the use-yaml-create-scaling-group.yaml file, run the following command to create the scaling group.

    Important
    aliyun ess ApplyScalingGroup --RegionId cn-hangzhou --Content "$(cat test-aliyun-cli-create-group.yaml)" --version 2022-02-22 --method POST --force

Parameters

Basic settings

Parameter

Description

Scaling group name

The name must be 2 to 64 characters in length. It must start with a letter, digit, or Chinese character, and can contain periods (.), underscores (_), and hyphens (-).

Scaling group type

Specifies the type of instances that provide computing power in the scaling group. Auto Scaling scales out or scales in instances of the specified type based on this setting.

  • ECS: All instances in the scaling group are ECS instances.

  • ECI: All instances in the scaling group are ECI instances.

Instance configuration source

Auto Scaling creates instances based on this setting. The following instance configuration sources are supported:

  • Launch template: Contains instance configuration information, such as key pairs, RAM roles, instance types, and network settings. Passwords are not included. This option is available only when scaling group type is set to ECS.

    If a single instance type is out of stock, scale-out activities may fail. You can select multiple instance types by using Advanced Launch Template Configurations to improve the success rate of scale-out activities. For more information, see Use multiple instance types in a launch template to improve the success rate of scale-outs.

  • Select Existing Instance: Select an existing instance. Auto Scaling automatically extracts the basic configuration information from the instance to create a default scaling configuration.

    Important
    • A scaling configuration extracted from an ECS instance includes basic information such as the instance type, network type, security group, and base image. The scaling configuration does not include the logon password or tags. The base image is the image used by the source instance and does not contain application data. If you want the scaling configuration to include all system configurations and data from the source instance, create a custom image from the instance.

  • Create from Scratch: You can create a scaling group without specifying a template for instance creation. After the scaling group is created, you can create a scaling configuration or specify a launch template. The procedure for creating a scaling configuration varies based on the scaling group type. For more information, see Create a scaling configuration (ECS instance) and Create a scaling configuration (ECI instance).

Note

When you create a scaling group from an instance in the ECS console, Auto Scaling automatically populates settings such as the instance configuration source and network type. You can keep the default settings.

Suspended Processes

You can suspend specific processes before you perform certain operations. For example, you can suspend the health check process before you stop an instance to prevent the instance from being marked as unhealthy and removed from the scaling group. The following processes can be suspended:

  • Scale-out Process: The scaling group rejects all scale-out requests.

  • Scale-in Process: The scaling group rejects all scale-in requests.

  • Health Check: Suspends the process that marks instances as unhealthy and removes them.

  • Scheduled Task: Prevents the associated scaling rule from being triggered at its scheduled time.

  • Event-triggered Task: Prevents the associated scaling rule from triggering when its associated event-triggered task enters an alert state.

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

Enable scaling group protection

If you enable this feature, you cannot delete the scaling group in the Auto Scaling console or by calling an API. This prevents accidental deletion of the scaling group.

Instance health check

When enabled, the scaling group periodically checks the running status of its instances. If an instance is not in the Running state, the scaling group considers it unhealthy and removes it. For more information, see Lifecycle of instances in a scaling group. The following options are available:

  • Disabled: Disables the health check feature.

  • Instance Status Check: Performs health checks on the status of instances in the scaling group.

  • Load balancer health check: Performs health checks based on the results from an Application Load Balancer (ALB) or Network Load Balancer (NLB). This option does not support Classic Load Balancer (CLB).

Maximum instance lifetime (sec)

The maximum amount of time that an instance can remain in the scaling group. When an instance's lifetime expires, Auto Scaling automatically replaces it with a new one.

Note

This parameter is available only when scaling group type is set to ECS.

Instance count

Parameter

Description

Minimum number of instances

If the number of instances in the scaling group falls below this minimum, Auto Scaling automatically adds instances to meet this limit.

Maximum number of instances

If the number of instances in the scaling group exceeds this maximum, Auto Scaling automatically removes instances to meet this limit. For more information about how instances are removed, see Configure a removal policy for a scaling group.

Desired number of instances

The number of instances that the scaling group attempts to maintain. For more information, see Desired number of instances.

Instance scaling

Important

For ECI scaling groups, you cannot modify the scaling policy, removal policy, or instance recycle mode. ECI scaling groups use the following default settings:

  • Scaling policy: Priority policy.

  • Removal policy: First, select instances from the oldest scaling configuration, and then remove the oldest instances.

  • Instance recycle mode: Release.

Parameter

Description

Scaling policy

By default, a scaling group uses the priority policy to perform scaling activities based on the order of the vSwitches that you configure. You can change the Scaling Policy to apply other policies. The scaling group offers several preset scaling policies, which are described as follows.

Important

You can change this configuration only when the Type is ECS and the Network Type is VPC. If the Type is ECI, the default Scaling Policy is the Priority.

  • Priority (Default)

    This policy scales instances based on the order of the vSwitches that you define. If an instance cannot be created in the zone of a higher-priority vSwitch, Auto Scaling automatically attempts to create the instance in the zone of the next-priority vSwitch.

  • Distribution Balancing

    This policy keeps instances evenly distributed across multiple zones after a scaling activity. This distribution helps achieve multi-zone disaster recovery. If the number of ECS instances becomes uneven across zones for reasons such as an instance being out of stock, you can perform a rebalancing operation to balance the distribution of ECS instances. For more information, see Rebalance ECS instances.

  • Cost Optimization

    Use the Cost Optimization when cost is a high priority. During a scaling activity, this policy attempts to create instances in ascending order of their vCPU unit price. If the scaling configuration includes multiple instance types that use the spot instance billing method, the policy prioritizes creating the corresponding spot instances. If spot instances cannot be created for reasons such as stock shortages, the policy automatically attempts to create pay-as-you-go instances. During a scale-in activity, the policy removes instances with the highest vCPU unit price first.

  • Custom Combination Policy

    This policy lets you customize the capacity distribution using a combination of settings. You can use this policy to adjust the ratio of on-demand instances to spot instances, balance capacity across zones, and select instance types.

For configuration instructions, see Configure a scaling policy.

Removal policy

This policy determines which instances to remove during a scale-in activity. If multiple instances match the criteria, Auto Scaling randomly removes one. This setting is supported only when scaling group type is ECS. The following options are available:

  • Oldest scaling configuration: Selects instances that were created from the earliest scaling configuration. Manually added instances are not associated with a scaling configuration or launch template and are not selected first. If all instances from the earliest configuration are removed and more instances need to be removed, manually added instances are removed at random.

    Important
    • In this context, a scaling configuration refers to both scaling configurations and launch templates.

    • The term "oldest" refers to when the scaling configuration or launch template was set in the scaling group, not the template version. For example:

      If a scaling group first uses version 2 of a launch template and is later reverted to version 1, version 2 is considered the oldest scaling configuration.

  • Oldest instance: Removes the oldest created instances first.

  • Newest instance: Removes the most recently created instances first.

  • Custom policy: Defines a custom removal policy based on a Function Compute service name, version, and function name to select instances.

When the removal policy is Oldest scaling configuration or Custom policy, multiple instances may match the criteria. You can set a secondary policy to further refine the selection. The following secondary policies are available:

  • None: No secondary filtering is performed.

  • Oldest instance: From the instances selected by the primary policy, selects the one that was created earliest.

  • Newest instance: From the instances selected by the primary policy, selects the one that was created most recently.

Note

The removal of instances is also affected by the scaling group's scaling policy. For more information, see Configure a removal policy for a scaling group.

Instance recycle mode

This mode determines what happens to an instance after it is removed from the scaling group. The following modes are available:

Note

This setting is available only when scaling group type is ECS and network type is VPC. For ECI scaling groups, the default mode is Release.

  • Release: The removed instance is released, and no resources are retained. During a scale-out activity, Auto Scaling creates new instances and adds them to the scaling group.

  • Stop in Economical Mode: The removed ECS instance is stopped and placed into economical mode. Some resources are retained and billed. During a scale-out activity, Auto Scaling reuses stopped instances during scale-out activities before creating new ones. This mode can improve scaling efficiency. For more information, see Use the economical mode to improve scaling efficiency.

    Important
    • To prevent data loss, do not store application data or logs on an instance, as it may be recycled.

    • Stopped instances may be released:

      • If you manually reduce the maximum number of instances to a value that is less than the total number of instances in all states (including stopped), Auto Scaling releases stopped ECS instances first.

      • If a stopped instance fails to be added back to the scaling group due to issues like insufficient inventory or an overdue payment, it is released.

    • The effect of this mode is subject to the economical mode for pay-as-you-go instances. For more information, see the "Conditions", "Applicable resources", and "Effects" sections of Economical mode.

  • Forcible Release: In a scale-in activity, the system forcibly releases instances that are in the Running (Running) state.

    Warning

    Forcibly releasing an instance is equivalent to a power-off. This action erases temporary data from memory and storage, and the data cannot be recovered. Use this option with caution.

  • Forcible Stop: In a scale-in activity, the system forcibly stops instances that are in the Running (Running) state.

    Warning

    Forcibly stopping an instance is equivalent to a power-off. This action erases temporary data from memory and storage, and the data cannot be recovered. Use this option with caution.

Network

Important

When Instance configuration source is Launch template or Select Existing Instance, settings such as network type, VPC, and Select vSwitch are automatically populated based on the template or selected instance. You can reconfigure the network settings for the scaling group as needed.

Parameter

Description

Network type

The network type for instances in the scaling group. VPC and classic network are supported.

Warning

The network type cannot be changed after the scaling group is created.

Important

We recommend that you select Virtual Private Cloud (VPC). VPC scaling groups support more flexible configurations, such as more flexible scaling policies, instance recycle modes, and association with Application Load Balancers (ALBs) and Network Load Balancers (NLBs). For more information about VPCs, see What is a Virtual Private Cloud (VPC)?.

VPC

This setting is available when network type is VPC. All instances in the scaling group are created in the selected VPC.

Warning

The VPC cannot be changed after the scaling group is created.

Select vSwitch

After selecting a VPC, you can select its vSwitches. All instances in the scaling group are created in the selected vSwitches.

Important

We recommend selecting vSwitches from multiple availability zones. This prevents scaling failures that can occur if a single zone runs out of stock. For ECS scaling groups, you can also change the scaling policy to control the distribution of instances across availability zones.

Associated services

Parameter

Description

Associate with RDS, Redis, and MongoDB instances

If instances in your scaling group need to access RDS, Redis, or MongoDB databases, you can use this setting to automatically add the internal IP addresses of new instances to the IP whitelist of the selected database instances.

Note

Associate with Classic Load Balancer (CLB)

After associating a scaling group with a CLB instance, instances added to the group are automatically registered as backend servers with the CLB instance to handle forwarded requests.

You can specify the server group to which the instances are added. The following types of server groups are supported:

  • Default Server Group: Receives frontend requests. If a listener is not configured with a virtual server group or a primary/secondary server group, requests are forwarded to the default server group.

  • Virtual Server Group: Use a virtual server group if you need to forward different requests to different backend servers, or forward requests based on domain names and URLs.

If you specify both a default server group and multiple virtual server groups, instances are added to all of them.

Note

A scaling group can be associated with a limited number of CLB instances and virtual server groups. To view or request a quota increase, go to Quota Center.

Associate with ALB/NLB server group

Important

This setting is available only when network type is VPC.

After associating a scaling group with an ALB or NLB server group, instances added to the scaling group are automatically registered as backend servers to handle requests. You must also specify the port and weight for the backend servers. The default weight is 50. A higher weight means the instance receives more requests. If the weight is 0, the instance receives no requests.

If you associate a scaling group with multiple ALB or NLB server groups, instances added to the scaling group are registered with all of them.

Note

A scaling group can be associated with a limited number of ALB and NLB server groups. To view or request a quota increase, go to Quota Center.

Other settings

Parameter

Description

Tags

Add tags to facilitate searching for and grouping scaling groups. For more information, see Tags.

Note

These tags apply to the scaling group itself. To add tags to instances within the scaling group, set them in the scaling configuration or launch template.

Tags to propagate to instances

After adding one or more tags to a scaling group, you can select which of these tags to propagate to the instances that are created during a scale-out activity.

Add existing instances

This setting is available if scaling group type is ECS and instance configuration source is Launch template or Select Existing Instance.

If you set a desired number of instances and add existing instances at the same time, the desired number of instances automatically increases. For example, if you set the desired number of instances to 1 and add 2 existing instances when you create a scaling group, the 2 instances are added to the group after it is created, and the desired number of instances becomes 3.

You can entrust the lifecycle of existing instances to the scaling group by selecting the Entrust Instance Lifecycle to Scaling Group checkbox.

  • If entrusted, an instance is automatically released when it is removed from the scaling group, either automatically (for example, due to being unhealthy) or manually.

  • If not entrusted, an instance is not released when it is removed from the scaling group.

Note

You can add subscription instances to a scaling group, but you cannot entrust their lifecycle to the group.

Configure notifications

Auto Scaling can send notifications by using SMS, internal messages, and email when a scaling activity succeeds, fails, or is rejected. For more information, see Configure notifications.

Resource group

Assign the scaling group to a resource group to isolate resources and manage permissions. For more information, see Manage scaling groups by using resource groups.

Sync scaling rules to Cloud Monitor

This feature can be enabled or disabled only when you create the scaling group. When enabled, the system creates and associates a Cloud Monitor application group with the scaling group, and its scaling rules are synchronized and displayed in the Cloud Monitor console.

YAML parameters

Supported Kubernetes YAML fields

When you deploy a scaling group for ECI using a Kubernetes YAML file, only the following YAML fields in a Kubernetes Deployment resource are supported.

Note

Refer to the sample Deployment on the official Kubernetes website for the YAML file's template structure. A YAML file primarily consists of the kind, metadata, and spec fields.

Supported Kubernetes YAML fields

  • kind: The resource type. The value must be Deployment.

  • metadata.name: The resource name. This field is not used by the scaling group. The k8s.aliyun.com/ess-scaling-group-name Annotation specifies the effective name.

  • spec.replicas: The number of pod replicas. This corresponds to the expected number of instances in the scaling group.

  • spec.template.spec: Defines the pod configuration. The following table describes the supported features.

    Feature

    YAML field

    Description

    DNS configuration

    dnsPolicy

    The DNS policy.

    dnsConfig.nameservers

    A list of IP addresses for DNS servers.

    dnsConfig.searches

    A list of DNS search domains.

    dnsConfig.options.name

    The name of the option.

    dnsConfig.options.value

    The value of the option.

    Container configuration

    containers.name

    The container name.

    containers.image

    The container image.

    containers.command

    The container startup command.

    containers.args

    The arguments for the container startup command.

    containers.imagePullPolicy

    The image pull policy.

    containers.stdin

    Specifies whether to allocate a buffer to stdin.

    containers.stdinOnce

    Specifies whether to allocate a one-time buffer to stdin.

    containers.tty

    Specifies whether to allocate a TTY.

    containers.ports

    containerPort

    The port number.

    protocol

    The protocol, such as TCP or UDP.

    containers.env

    name

    The name of the environment variable.

    value

    The value of the environment variable.

    containers.resources

    requests.cpu

    The CPU request.

    requests.memory

    The memory request.

    limits.cpu

    The CPU limit.

    limits.memory

    The memory limit.

    limits.nvidia.com/gpu

    You can add an Annotation to the Pod metadata to specify the GPU specifications.

    After you specify the GPU specifications, you must add the nvidia.com/gpu field in the container's resources section to declare the required GPU resources.

    containers.securityContext

    runAsUser

    The user ID used to run the container.

    readOnlyRootFilesystem

    Specifies whether the root file system of the container is read-only.

    capabilities.add

    Specifies the capabilities to add to processes in the container.

    containers.volumeMounts

    name

    This must match the name of a volume.

    mountPath

    The mount path of the volume in the container.

    mountPropagation

    Determines how mounts are propagated from the host to the container and vice versa.

    readOnly

    Valid values:

    • true: Mounts the volume in read-only mode.

    • false: Mounts the volume in read-write mode.

    Default value: false.

    subPath

    The path within the volume.

    containers.livenessProbe

    • initialDelaySeconds

    • periodSeconds

    • successThreshold

    • timeoutSeconds

    • failureThreshold

    • exec.command

    • tcpSocket.port

    • httpGet.scheme

    • httpGet.port

    • httpGet.path

    For more information, see Configure liveness, readiness, and startup probes.

    containers.readinessProbe

    • initialDelaySeconds

    • periodSeconds

    • successThreshold

    • timeoutSeconds

    • failureThreshold

    • exec.command

    • tcpSocket.port

    • httpGet.scheme

    • httpGet.port

    • httpGet.path

    init container configuration

    initContainers.name

    The name of the init container.

    initContainers.image

    The image of the init container.

    initContainers.command

    The startup command of the init container.

    initContainers.args

    The arguments for the init container startup command.

    initContainers.imagePullPolicy

    The image pull policy for the init container.

    initContainers.env

    name

    The name of the environment variable for the init container.

    value

    The value of the environment variable for the init container.

    initContainers.resources

    requests.cpu

    The CPU request for the init container.

    requests.memory

    The memory request for the init container.

    limits.cpu

    The CPU limit for the init container.

    limits.memory

    The memory limit for the init container.

    limits.nvidia.com/gpu

    Specifies the GPU resources that the init container requires.

    initContainers.securityContext

    capabilities.add

    Specifies the capabilities to add to processes in the init container.

    initContainers.volumeMounts

    name

    The name of the volume used by the init container. This must match the name of a volume.

    mountPath

    The mount path of the volume in the init container.

    mountPropagation

    Determines how mounts are propagated from the host to the init container and vice versa.

    readOnly

    Valid values:

    • true: Mounts the volume in read-only mode.

    • false: Mounts the volume in read-write mode.

    Default value: false.

    subPath

    The path within the volume.

    Volume configuration

    volumes.nfs

    name

    The name of the volume.

    server

    The address of the NFS server (NAS mount target).

    path

    The path of the NFS volume.

    readOnly

    Specifies whether the volume is read-only.

    volumes.emptyDir

    sizeLimit

    The size limit for the temporary emptyDir volume. The value must include a unit, such as Gi or Mi.

    medium

    The storage medium for the emptyDir volume. Valid values:

    • Empty string (default): Uses the node's file system as the storage medium.

    • Memory: Uses memory as the storage medium.

    volumes.flexVolume

    driver

    The name of the driver for FlexVolume.

    options

    A map of FlexVolume options, specified as key-value pairs in JSON format.

    For example, when you mount a cloud disk using FlexVolume, the format of options is {"volumeId":"d-2zehdahrwoa7srg****","performanceLevel": "PL2"}.

    Graceful shutdown

    terminationGracePeriodSeconds

    The duration, in seconds, for the container to shut down gracefully.

Extended annotations

When you deploy an ECI-based scaling group using a Kubernetes YAML file, you can only extend the following annotations.

Extended annotations in metadata

Parameter

Description

Example

k8s.aliyun.com/ess-scaling-group-name

The name of the scaling group.

ess-group-test

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

The minimum number of instances in the scaling group. The default is 0.

0

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

The maximum number of instances in the scaling group. The default is max(replicas, 30).

20

Extended annotations in spec.template.spec

For more information about annotations, see ECI Pod annotations.

Parameter

Example value

Description

k8s.aliyun.com/eci-ntp-server

100.100.*.*

The Network Time Protocol (NTP) server.

k8s.aliyun.com/eci-use-specs

2-4Gi

Specifies the ECI instance types. You can specify multiple types. For more information, see Create Pods by specifying multiple specifications.

k8s.aliyun.com/eci-vswitch

vsw-bp1xpiowfm5vo8o3c****

The ID of the vSwitch. You can specify multiple vSwitch IDs to enable deployment across multiple availability zones.

k8s.aliyun.com/eci-security-group

sg-bp1dktddjsg5nktv****

The ID of the security group. The following requirements apply:

  • You can specify up to five security groups.

  • The specified security groups must be in the same VPC.

  • The specified security groups must be of the same type.

k8s.aliyun.com/eci-sls-enable

"false"

Set to "false" to disable log collection for the Pod. When using Simple Log Service (SLS) CRDs for logging, apply this annotation to Pods where collection is not required. This prevents automatic Logtail configuration creation and conserves resources.

k8s.aliyun.com/eci-spot-strategy

SpotAsPriceGo

The bidding policy for preemptible instances. Valid values:

  • SpotWithPriceLimit: Sets a maximum hourly price for the preemptible instances. This policy also requires the k8s.aliyun.com/eci-spot-price-limit annotation.

  • SpotAsPriceGo: The system automatically bids at the current market price.

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

"0.5"

The maximum hourly price for the preemptible instances. The value can have up to three decimal places. This annotation applies only when

k8s.aliyun.com/eci-spot-strategy

is set to

SpotWithPriceLimit

.

k8s.aliyun.com/eci-with-eip

"true"

Set to "true" to automatically create and associate an Elastic IP address (EIP).

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

default

The DataCache bucket. This annotation is required to create a Pod that uses a DataCache.

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

PL1

The performance level of the disk created from the DataCache. By default, this creates an Enhanced SSD (ESSD) disk with a performance level of PL1.

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

"40000"

The provisioned read/write IOPS for an ESSD AutoPL disk. The value must be within the range of 0 to min{50000, 1000 * Capacity - Baseline IOPS}. The baseline IOPS is calculated as min{1800 + 50 * Capacity, 50000}. For more information, see ESSD AutoPL disks.

Adding this annotation creates an ESSD AutoPL disk from the DataCache.

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

"true"

Enables or disables burst for an ESSD AutoPL disk. For more information, see ESSD AutoPL disks.

Adding this annotation creates an ESSD AutoPL disk from the DataCache.

k8s.aliyun.com/eci-custom-tags

"env:test,name:alice"

Specifies the tags to bind to the instance. You can bind a maximum of three tags. Use a colon (:) to separate a key from its value and a comma (,) to separate tags.

For more information about annotations, see ECI Pod annotations.