All Products
Search
Document Center

Create an elastic container instance equipped with local disks

Last Updated: Apr 14, 2021

This topic describes how to create and use an elastic container instance equipped with local disks.

Background information

You can specify Elastic Compute Service (ECS) instance types equipped with local disks to create elastic container instances equipped with local disks. Local disks are physically located on the same physical servers as the elastic container instances to which the disks are mounted. Local disks are cost-effective and provide high random IOPS, high throughput, and low latency. Local disks reside on single physical servers, which increases the risks of single points of failure (SPOFs). For more information, see Local disks.

The following ECS instance families equipped with local disks are supported:

  • d1, big data instance family, which includes multiple instance types such as ecs.d1.2xlarge

  • d1ne, big data instance family with enhanced network performance, which includes multiple instance types such as ecs.d1ne.2xlarge

  • i2, instance family equipped with local SSDs, which includes multiple instance types such as ecs.i2.xlarge

  • i2g, instance family equipped with local SSDs, which includes multiple instance types such as ecs.i2g.2xlarge

  • gn5, GPU-accelerated compute optimized instance family, which includes multiple instance types such as ecs.gn5-c4g1.xlarge.

    Note

    gn5 is a GPU-accelerated instance family. If you select this instance family, you must specify GPU-related parameters in addition to local disk-related parameters. For more information, see Create a GPU-accelerated elastic container instance.

For more information, see:

Kubernetes mode

You can specify an ECS instance type equipped with local disks by adding annotations to the YAML file. Take note of the following items:

  • Add annotations to the spec.template.metadata section.

  • Local disks have the same lifecycle as the elastic container instances to which the disks are attached. You cannot mount local disks as persistent volumes (PVs) but can mount local disks as flex volumes.

Sample code:

apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: nginx-i2
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
      annotations:
        k8s.aliyun.com/eci-use-specs: "ecs.i2.4xlarge"  #Specify an ECS instance type equipped with local disks.
    spec:
      containers:
      - name: nginx
        image: nginx
        volumeMounts:
          - name: disk1
            mountPath: /data1
          - name: disk2
            mountPath: /data2
      volumes:       #Attach local disks to the elastic container instance. Make sure that the number of specified local disks does not exceed the number of local disks supported by the specified ECS instance type.
        - name: disk1
          flexVolume:
            driver: alicloud/local-disk
            fsType: ext4
        - name: disk2
          flexVolume:
            driver:  alicloud/local-disk
            fsType: ext4

API mode

When you call the CreateContainerGroup operation to create an elastic container instance, you can use the InstanceType parameter to specify ECS instance types and the volume-related parameters to attach local disks. The following table describes the parameters. For more information, see CreateContainerGroup.

Parameter

Type

Required

Example

Description

InstanceType

String

No

ecs.gn6v-c8g1.2xlarge

The ECS instance type equipped with local disks. The following instance families equipped with local disks are supported: d1, d1ne, i2, i2g, and gn5. You can specify up to five ECS instance types at a time and separate the ECS instance types with commas (,). Example: ecs.d1.2xlarge,ecs.d1ne.2xlarge.

Volume.N.Name

String

No

1

The name of the volume.

Volume.N.Type

String

No

flexvolume

The type of volume N.

Volume.N.FlexVolume.Driver

String

No

alicloud/local-disk

The name of the FlexVolume driver for volume N. Set the value to alicloud/local-disk.

Volume.N.FlexVolume.FsType

String

No

ext4

The type of the file system for volume N. The default value is determined by the script of FlexVolume.

Notice

When you create an elastic container instance equipped with local disks, make sure that the number of volumes does not exceed the number of local disks supported by each of the specified ECS instance type. If the specified ECS instance type has multiple local disks, the disks can be attached in any order because they all have the same specifications.