All Products
Search
Document Center

Mount a ConfigMap volume to an elastic container instance

Last Updated: Nov 15, 2021

This topic describes how to mount a ConfigMap volume to an elastic container instance. You can perform this operation to mount files to your container.

Prerequisites

Your Kubernetes cluster is deployed with Virtual Kubelet.

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 an elastic container instance to a Kubernetes cluster.

Configuration example

You can mount a ConfigMap volume to an elastic container instance in the same way that you mount a ConfigMap volume to a Kubernetes cluster. Perform the following operations:

  1. Create a ConfigMap.

    kubectl create configmap demo --from-literal=test=configmap

    Run the following command to view the configuration items of the ConfigMap:

    kubectl get configmap demo -o yaml

    The following output is returned.

    apiVersion: v1
    data:
      test: configmap
    kind: ConfigMap
    metadata:
      creationTimestamp: "2020-01-20T12:54:42Z"
      name: demo
      namespace: default
      resourceVersion: "15340926"
      selfLink: /api/v1/namespaces/default/configmaps/demo
      uid: 07119167-3b84-11ea-8c0c-4ac7cb9a****
  2. Prepare a YAML configuration file.

    vim test-configmap.yaml

    The following code provides an example test-configmap.yaml file.

    apiVersion: v1
    kind: Pod
    metadata:
      name: test-configmap
      labels: 
        alibabacloud.com/eci: "true"   
    spec:
      containers:
        - name: nginx
          image: nginx:latest
          volumeMounts:
          - name: config-volume
            mountPath: /cache-test
      volumes:
        - name: config-volume
          configMap:
            name: demo
            items:
            - key: test
              path: keys
      restartPolicy: Always
  3. Deploy a pod.

    kubectl create -f test-configmap.yaml
  4. View the mount result.

    Run the ls command to view the file directory in the pod. You can see the ConfigMap volume is mounted to the elastic container instance.

    Mount a ConfigMap volume to an elastic container instance