All Products
Search
Document Center

Mount an emptyDir volume

Last Updated: Oct 11, 2021

This topic describes how to mount an emptyDir volume to an elastic container instance.

Prerequisites

Virtual Kubelet is deployed in a Kubernetes cluster.

Note

Alibaba Cloud Serverless Kubernetes (ASK) clusters are integrated with Virtual Kubelet. For other types of clusters, you must manually deploy Virtual Kubelet. For more information, see Connect Kubernetes to Elastic Container Instance.

Configuration example

You can mount an emptyDir volume to an elastic container instance in the same way that you mount an emptyDir volume to a Kubernetes instance. The following example shows how to mount an emptyDir volume:

  1. Prepare a YAML configuration file.

    vim empty_dir.yaml

    The following example shows the content of the empty_dir.yaml file.

    apiVersion: v1
    kind: Pod
    metadata:
      name: test-pd
    spec:
      containers:
      - image: nginx:latest
        name: test-container
        volumeMounts:
        - mountPath: /cache-test
          name: cache-volume
      volumes:
      - name: cache-volume
        emptyDir: {}
  2. Deploy a pod.

    kubectl create -f empty_dir.yaml
  3. View the mount result.

    Run the ls command to view the file directory in the pod. The mount directory /cache-test of the emptyDir volume was generated in the pod.

    empty