All Products
Search
Document Center

Create a custom-sized temporary storage space

Last Updated: May 11, 2021

By default, Elastic Container Instance provides 20 GiB of storage capacity free of charge. If you want to increase the storage capacity, you can create a custom-sized temporary storage space. This topic describes how to create a custom-sized temporary storage space.

Background information

The default system disk size of an elastic container instance is 40 GiB, and 20 GiB of the system disk is occupied by the operating system. If you need more than 20 GiB of storage space, you can create a custom-sized temporary storage space. The created temporary storage space is billed at the pay-as-you-go price of performance level-1 (PL1) enhanced SSDs (ESSDs). The price of PL1 ESSDs varies from region to region. For more information, go to the Pricing tab of the Elastic Compute Service product page.

Kubernetes mode (add annotations)

You can add annotations to specify the size of a temporary storage space by using the k8s.aliyun.com/eci-extra-ephemeral-storage field. The following steps provide related sample code:

  1. Prepare the YAML file and add annotations to configure the temporary storage space.

    In the following example, the YAML file is named extra-storage.yaml and contains the following information:

    apiVersion: v1
    kind: Pod
    metadata:
      name: test
      annotations:
        k8s.aliyun.com/eci-extra-ephemeral-storage: "50Gi"  # Specify the size of the temporary storage space.
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        imagePullPolicy: IfNotPresent
      restartPolicy: Always
  2. Create a pod.

    kubectl apply -f extra-storage.yaml
  3. Check whether the temporary storage space takes effect.

    • Check the size of the temporary storage space.

      kubectl describe pod test | grep k8s.aliyun.com/eci-extra-ephemeral-storage

      The following output indicates that 50 GiB of temporary storage space is added:

      k8s.aliyun.com/eci-extra-ephemeral-storage: 50Gi
    • Run the exec command to check whether the file system partitions of the container are extended.

      kubectl exec -it test -- sh
      df -h

      The following output indicates that about 70 GiB of storage space is available. The total storage space consists of 50 GiB of added temporary storage space and 20 GiB of available storage space on the system disk.

      Filesystem      Size  Used Avail Use% Mounted on
      overlay          88G  3.4G   81G   4% /
      tmpfs            64M     0   64M   0% /dev
      tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
      /dev/root        88G  3.4G   81G   4% /etc/hosts
      shm              64M     0   64M   0% /dev/shm
      tmpfs           2.0G   12K  2.0G   1% /run/secrets/kubernetes.io/serviceaccount
      tmpfs           2.0G     0  2.0G   0% /proc/acpi
      tmpfs           2.0G     0  2.0G   0% /sys/firmware

Kubernetes mode (specify an emptyDir volume)

You can specify an emptyDir volume to create a temporary storage space. If the emptyDir volume that you specify does not exceed 20 GiB, the temporary storage space is not created. If the emptyDir volume exceeds 20 GiB, the extra volume capacity is used as the temporary storage space. The following steps provide related sample code:

  1. Prepare the YAML file and declare an emptyDir volume.

    In the following example, the YAML file is named emptyvolume.yaml and contains the following information:

    apiVersion: v1
    kind: Pod
    metadata:
      name: test-pd
    spec:
      containers:
      - image: nginx:latest
        name: nginx
        volumeMounts:
        - mountPath: /extra-storage
          name: cache-volume
      volumes:
      - name: cache-volume
        emptyDir: {"sizeLimit": "30Gi"}    # Specify the emptyDir volume. If the volume exceeds 20 GiB, the extra volume capacity is used as the temporary storage space.
  2. Create a pod.

    kubectl apply -f emptyvolume.yaml
  3. Check whether the temporary storage space takes effect.

    kubectl describe pod test-pd | grep k8s.aliyun.com/eci-extra-ephemeral-storage

    The following output indicates that 10 GiB of temporary storage space is added:

    k8s.aliyun.com/eci-extra-ephemeral-storage: 10Gi

API mode

When you call the CreateContainerGroup operation to create an elastic container instance, you can use the EphemeralStorage parameter to specify the size of a temporary storage space. The following table describes the parameter. For more information, see CreateContainerGroup.

Parameter

Type

Required

Example

Description

EphemeralStorage

Integer

No

50

The size of the temporary storage space. You are charged for the temporary storage space based on the pay-as-you-go price of PL1 ESSDs. Unit: GiB.

You can also use an SDK to create an elastic container instance. The following sample code shows how to use SDK for Python to create an elastic container instance that has a custom-sized temporary storage space:

#!/usr/bin/env python
#coding=utf-8

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkeci.request.v20180808.CreateContainerGroupRequest import CreateContainerGroupRequest

client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-hangzhou')

request = CreateContainerGroupRequest()
request.set_accept_format('json')

request.set_SecurityGroupId("sg-uf6biempwqvodk7*****")
request.set_VSwitchId("vsw-uf6mhqg2wiq9iifhn*****")
request.set_ContainerGroupName("test")
request.set_Containers([
  {
    "Image": "nginx",
    "Name": "nginx"
  }
])
request.set_EphemeralStorage(50) # Specify the size of the temporary storage space.

response = client.do_action_with_exception(request)
# python2:  print(response) 
print(str(response, encoding='utf-8'))