All Products
Search
Document Center

Specify the number of vCPUs and memory size to create an elastic container instance

Last Updated: May 24, 2021

If you do not have specific requirements such as for GPUs and local disks, we recommend that you specify the number of vCPUs and memory size instead of Elastic Compute Service (ECS) instance types to create elastic container instances. The system can then try a variety of ECS instance types based on the specified vCPU and memory specifications to select a suitable instance type. This method provides better elasticity and resource provisioning than the method of specifying ECS instance types.

Background information

If your specified number of vCPUs or memory size is invalid when you create an elastic container instance, the system adjusts the number or size based on the specifications supported by Elastic Container Instance. The following table describes the specifications supported by Elastic Container Instance.

Note

The following features are not supported:

  • IPv6.

  • Multiple elastic network interfaces (ENIs). Each elastic container instance can have a single ENI bound.

vCPU

Memory (GiB)

emptyDir volume (GiB)

Bandwidth (bidirectional), Gbit/s

Packet forwarding rate (bidirectional), Kpps

ENI queues

0.25

0.5 and 1

20

0.1

4

1

0.5

1 and 2

20

0.2

5

1

1

2, 4, and 8

20

0.5

5

1

2

2, 4, 8, and 16

20

1

30

2

4

4, 8, 16, and 32

20

1.5

50

2

8

8, 16, 32, and 64

20

2.0

80

4

12

12, 24, 48, and 96

20

2.5

90

4

16

16, 32, 64, and 128

20

3.0

100

4

24

48, 96, and 192

20

4.5

150

6

32

64, 128, and 256

20

6.0

200

8

52

96, 192, and 384

20

12.5

300

32

64

128, 256, and 512

20

20.0

400

16

You can use one of the following methods to create an elastic container instance by specifying the number of vCPUs and memory size:

Specify the number of vCPUs and memory size for containers in an elastic container instance

This method is the default method of creating pods in Kubernetes. You can create a maximum of 20 containers within each elastic container instance and specify the vCPU and memory specifications of each container. For each elastic container instance, the total vCPU and memory specifications of all containers must be less than or equal to the vCPU and memory specifications of the instance. If the total vCPU or memory specifications of the containers exceed those of the instance, the system adjusts the container specifications and then bills you based on the new specifications.

Kubernetes mode

You can specify the number of vCPUs and memory size in the request parameters for a container. 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
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9 # replace it with your exactly <image_name:tags>
        command: sleep 3600
        ports:
        - containerPort: 80
        resources:
          requests:
            cpu: "500m"      #Specify the number of vCPUs for the nginx container.
            memory: "1024Mi"   #Specify the memory size for the nginx container.
      - name: busybox
        image: busybox:latest # replace it with your exactly <image_name:tags>
        ports:
        - containerPort: 8080
        resources:
          requests:
            cpu: "500m"   #Specify the number of vCPUs for the busybox container.
            memory: "1024Mi"  #Specify the memory size for the busybox container.
      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 Container.N.Cpu and Container.N.Memory parameters to specify the number of vCPUs and memory size for each container. The following table describes the parameters. For more information, see CreateContainerGroup.

Parameter

Type

Required

Example

Description

Container.N.Cpu

Float

No

2

The number of vCPUs of container N. N specifies the serial number of the container. Maximum value of N: 20.

Container.N.Memory

Float

No

4

The memory size of container N. Unit: GiB. N specifies the serial number of the container. Maximum value of N: 20.

Console mode

When you create an elastic container instance by using the elastic container instance buy page in the Elastic Container Instance console, you configure the number of vCPUs and memory size in the Advanced Settings section for each container. The total vCPU and memory specifications of all containers in an elastic container instance must be less than or equal to the vCPU and memory specifications of the instance.

Container Configurations

Specify the number of vCPUs and memory size for an elastic container instance

When this method is used, the system tries a variety of ECS instance types based on the specified number of vCPUs and memory size to select a suitable ECS instance type for better elasticity and resource provisioning. This method has the following benefits:

  • You do not need to specify the number of vCPUs, memory size, or resource limits for containers in the elastic container instance. This provides the containers with greater flexibility to share the requested resources.

  • In the genetic computation and Istio scenarios, the service framework automatically deploys sidecar containers in pods. You can seamlessly connect Elastic Container Instance to the service framework by specifying the number of vCPUs and memory size for elastic container instances.

Kubernetes mode

You can add annotations to metadata in the configuration file of the pod to specify the number of vCPUs and memory size for an elastic container instance. 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 : "2-4Gi"   #Specify the number of vCPUs and memory size of the elastic container instance.
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9 # replace it with your exactly <image_name:tags>
        ports:
        - containerPort: 80
      - name: busybox
        image: busybox:latest # replace it with your exactly <image_name:tags>
        ports:
        - containerPort: 80
        resources:
          limits:
            cpu: "500m"     #Specify the maximum number of vCPUs for the container.
            memory: "1024Mi"   #Specify the maximum memory size for the container.
    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 Cpu and Memory parameters to specify the number of vCPUs and memory size for the elastic container instance. The following table describes the parameters. For more information, see CreateContainerGroup.

Parameter

Type

Required

Example

Description

Cpu

Float

No

2

The number of vCPUs of the elastic container instance.

Memory

Float

No

4

The memory size of the elastic container instance. Unit: GiB.

Console mode

When you create an elastic container instance by using the elastic container instance buy page in the Elastic Container Instance console, you can specify the number of vCPUs and memory size in the Container Group Configuration section.

Container Group Configuration