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