All Products
Search
Document Center

Specify multiple instance types to create an elastic container instance

Last Updated: May 24, 2021

When you create a large number of elastic container instances, some resources in the specified region and zone may be insufficient. To ensure that resources are sufficient to create the elastic container instances, we recommend that you specify multiple instance types across multiple zones for the pods.

Background information

You can specify multiple Elastic Compute Service (ECS) instance types in the k8s.aliyun.com/eci-use-specs annotation in the configuration file of a pod to create an elastic container instance. If the instance cannot be created due to insufficient resources of a specified ECS instance type, the system attempts to use the next instance type specified in the annotation to create the elastic container instance. When the system is attempting to create the elastic container instance, the pod remains in the Pending state. We recommend that you specify multiple ECS instance types to ensure that resources are sufficient to create the elastic container instance.

Note

The specified ECS instance types take effect at the pod level and affect only how a single pod is created.

You can specify multiple instance type across multiple zones to further improve the success rate of creating elastic container instances. For more information, see Specify multiple zones to create an elastic container instance.

Kubernetes mode

You can add annotations to metadata in the configuration file of the pod to specify multiple ECS instance types. Specify multiple ECS instance types in the order that they are to be prioritized for use. Sample code:

apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: nginx-deployment-basic
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
      annotations:
        k8s.aliyun.com/eci-use-specs: ecs.c5.large,ecs.c6.large,ecs.sn1ne.large,ecs.g5.large  #Specify ECS instance types.
    spec:
    #  nodeSelector:
    #    env: test-team
      containers:
      - name: nginx
        image: nginx:1.7.9 # replace it with your exactly <image_name:tags>
        ports:
        - containerPort: 80
      nodeName: virtual-kubelet
  #Specify a virtual node name to schedule the pod to Elastic Container Instance in a Container Service for Kubernetes (ACK) cluster.

API mode

When you call the CreateContainerGroup operation to create an elastic container instance, you can use the InstanceType parameter to specify one or more ECS instance types. The following table describes the parameter. For more information, see CreateContainerGroup.

Parameter

Type

Required

Example

Description

InstanceType

String

No

ecs.c5.xlarge,ecs.g5.xlarge

The ECS instance types. You can specify up to five ECS instance types at a time. Separate multiple instance types with commas (,). Example: ecs.c5.xlarge,ecs.g5.xlarge.

Note

We recommend that you specify multiple instance types across multiple zones to create elastic container instances. You can use the VSwitchId parameter to specify multiple zones and the InstanceType parameter to specify multiple instance types.