All Products
Search
Document Center

Create a custom temporary storage space

Last Updated: Sep 15, 2021

By default, Elastic Container Instance provides 20 GiB of storage space free of charge. If you require more storage space, you can create a temporary storage space. This topic describes how to create a temporary storage space.

Background information

The default system disk size of an elastic container instance is 40 GiB, where 20 GiB is occupied by the operating system. If you need more than 20 GiB of storage space, you can create a 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, see the Pricing tab of the Elastic Compute Service product page.

Kubernetes mode

For Kubernetes deployments, you can use the following methods to create a temporary storage space:

  • Method 1: Add annotations

    You can add annotations to specify the value of the k8s.aliyun.com/eci-extra-ephemeral-storage field to the size of the temporary storage space that you want to create.

  • Method 2: Specify an emptyDir volume

    You can specify an emptyDir volume to create a temporary storage space. If the specified size of emptyDir volume does not exceed 20 GiB, a temporary storage space is not created. If the specified size of emptyDir volume exceeds 20 GiB, a temporary storage space is created for the excess size.

  • Method 3: Use resource requests
    You can use resource requests to declare the size of ephemeral storage for a container. If the declared size does not exceed 20 GiB, a temporary storage space is not created. If the declared size exceeds 20 GiB, a temporary storage space is created for the excess size.
Note

The preceding methods can be used to create temporary storage space, but the temporary storage space created by each method may be different.

  • When you add annotations to create a temporary storage space, the size of the created temporary storage space is the size that you specify.

  • When you specify an emptyDir volume or declare the storage space of a container in a resource request to create a temporary storage space, the size of the created temporary storage space may be different from the value that you specify due to the image cache.

The following procedure describes how to configure the size of a temporary storage space.

  1. Prepare a YAML file.

    In the following examples, the YAML file is named extra-storage.yaml. The following examples show the contents of the YAML file of the preceding methods:

    • Example 1: Add annotations

      apiVersion: v1
      kind: Pod
      metadata:
        name: test
        annotations:
          k8s.aliyun.com/eci-extra-ephemeral-storage: "30Gi" # Specify the size of the temporary storage space.
      spec:
        containers:
        - name: nginx
          image: nginx:latest
          imagePullPolicy: IfNotPresent
        restartPolicy: Always
    • Example 2: Specify an emptyDir volume

      apiVersion: v1
      kind: Pod
      metadata:
        name: test
      spec:
        containers:
        - image: nginx:latest
          name: nginx
          volumeMounts:
          - mountPath: /extra-storage
            name: cache-volume
        volumes:
        - name: cache-volume
          emptyDir: {"sizeLimit": "50Gi"} # Specify the size of the emptyDir volume. If the specified size of emptyDir volume exceeds 20 GiB, a temporary storage space is created.
    • Example 3: Specify the resource-related request of a container

      apiVersion: v1
      kind: Pod
      metadata:
        name: test
      spec:
        containers:
        - name: nginx
          image: nginx:latest
          imagePullPolicy: IfNotPresent
          resources: 
            requests: {"ephemeral-storage": "50Gi"} # Declare the size of ephemeral storage in the resource request of the container. If the size of ephemeral storage exceeds 20 GiB, a temporary storage space is created for the excess size.
  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 a 30 GiB of temporary storage space is added:

      k8s.aliyun.com/eci-extra-ephemeral-storage: 30Gi
    • 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 the total storage space is about 70 GiB, which consists of 20 GiB of the system disk that is occupied by the operating system, 20 GiB of default available storage space, and 30 GiB of temporary storage space.

      Filesystem      Size  Used Avail Use% Mounted on
      overlay          69G  4.7G   61G   8% /
      tmpfs            64M     0   64M   0% /dev
      tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
      /dev/root        69G  4.7G   61G   8% /etc/hosts
      shm              64M     0   64M   0% /dev/shm
      tmpfs           1.9G   12K  1.9G   1% /run/secrets/kubernetes.io/serviceaccount
      tmpfs           1.9G     0  1.9G   0% /proc/acpi
      tmpfs           1.9G     0  1.9G   0% /sys/firmware

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. 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 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'))