• Cloud Container Engine

cce
  1. Help Center
  2. Cloud Container Engine
  3. User Guide 2.0
  4. Configuration Center
  5. Using a Configuration Item

Using a Configuration Item

The following example shows how to use ConfigMap.

apiVersion: v1
kind: ConfigMap
metadata:
  name: cce-configmap
data:
  SPECIAL_LEVEL: Hello
  SPECIAL_TYPE: CCE

When ConfigMap is used in a pod, the pod and ConfigMap must be in the same cluster and namespace.

Mounting a Configuration Item to an Application Data Volume

The configuration item can also be used in a data volume. You only need to mount the configuration item to an application when creating the application. After the mounting is complete, a configuration file with key as the file name and value as the file content is generated.

apiVersion: v1 
kind: Pod 
metadata: 
  name: configmap-pod-4 
spec: 
  containers: 
    - name: test-container 
      image: busybox 
      command: [ "/bin/sh", "-c", "ls /etc/config/" ]   ## List names of files in this directory.
      volumeMounts: 
      - name: config-volume 
        mountPath: /etc/config                          ## Mount the configuration item to the /etc/config directory.
  volumes: 
    - name: config-volume 
      configMap: 
        name: cce-configmap 
  restartPolicy: Never

After the pod is run, the SPECIAL_LEVEL and SPECIAL_TYPE files are generated in the /etc/config directory. The contents of the files are Hello and CCE, respectively. Also, the following file names will be displayed.

SPECIAL_TYPE 
SPECIAL_LEVEL

To mount ConfigMap to a data volume, you can also perform operations on the CCE console. When creating an application, add a container image. Then, select Data Storage > Local Disks, click Add Local Disk, and select ConfigMap. For details, see ConfigMap.