All Documents
Current Document

Content is empty

If you don't find the content you expect, please try another search term

Documentation

Manage ConfigMaps

Last updated:2021-05-11 10:41:17

A ConfigMap is an API object that stores non-confidential data in key-value pairs. It decouples configuration files from container images to enhance the portability of containerized applications. A ConfigMap contains key-value pairs. You can create a ConfigMap in the KCE console and use it when you mount a volume, define an environment variable, or run a command.

Operations in the KCE console

Create a ConfigMap

  1. Log in to the KCE console.
  2. In the left navigation pane, click Cluster.
  3. Click the ID of the cluster in which you want to create a ConfigMap. The cluster details page appears.
  4. In the left navigation pane, choose Configuration Management > ConfigMap. The ConfigMap list page appears.
  5. Click Create. On the Create ConfigMap page, complete the following configurations:
    • Name: the name of the ConfigMap to be created.
    • Namespace: the namespace of the cluster to which the ConfigMap belongs.
    • Configuration Item: the variables of the ConfigMap. You can define the variable names and variable values as required.
  6. Click Create.

Use a ConfigMap

Method 1: Mount a volume of the ConfigMap type
  1. Log in to the KCE console.
  2. In the left navigation pane, click Cluster.
  3. Click the ID of the cluster in which you want to use a ConfigMap. The cluster details page appears.
  4. In the left navigation pane, click Workload and select any type of workload. The corresponding list page appears. For example, in the left navigation pane, choose Workload > Deployment to go to the Deployment list page.
  5. Click Create. The Create Deployment page appears.
  6. Set basic information and proceed to Deployment Configuration. In the Deployment Configuration step, click Add Volume, select ConfigMap for Type, and then enter the volume name, as shown in the following figure. image.png
  7. Click Select ConfigMap. In the Set ConfigMap dialog box, complete the following configurations:
    • Select ConfigMap: Select a ConfigMap as required.
    • Mount Options: Select Mount All or Mount with Specified Key as required.

Note: When you select Mount with Specified Key, you can mount the ConfigMap to a specific path by setting Items. For example, if the mount path is /etc/config and the subpath is dev, data will be stored in /etc/config/dev.

  1. After all configurations are completed, click Create.
Method 2: Define an environment variable for a container
  1. Log in to the KCE console.
  2. In the left navigation pane, click Cluster.
  3. Click the ID of the cluster in which you want to use a ConfigMap. The cluster details page appears.
  4. In the left navigation pane, click Workload and select any type of workload. The corresponding list page appears. For example, in the left navigation pane, choose Workload > Deployment to go to the Deployment list page.
  5. Click Create. The Create Deployment page appears. Set basic information and proceed to Deployment Configuration. In the Container configuration section, click Add for Environment Variable, as shown in the following figure.

image.png

  1. Select Reference ConfigMap for Add Method, enter the variable name, and then select a variable value or a variable reference.

  2. After all configurations are completed, click Create.

Update a ConfigMap

  1. Log in to the KCE console.
  2. In the left navigation pane, click Cluster.
  3. Click the ID of the cluster in which you want to update a ConfigMap. The cluster details page appears.
  4. In the left navigation pane, choose Configuration Management > ConfigMap. The ConfigMap list page appears.
  5. Find the ConfigMap that you want to update and click Edit YAML in the Operation column.
  6. On the UpdateConfigMap page, modify the configurations as required and click Update.

Delete a ConfigMap

  1. Log in to the KCE console.
  2. In the left navigation pane, click Cluster.
  3. Click the ID of the cluster in which you want to delete a ConfigMap. The cluster details page appears.
  4. In the left navigation pane, choose Configuration Management > ConfigMap. The ConfigMap list page appears.
  5. Find the ConfigMap that you want to delete and click Delete in the Operation column.
  6. In the message that appears, click OK.

Operations by using kubectl

Create a ConfigMap

Method 1: Use a YAML file

Sample configmap-test.yaml file:

apiVersion: v1
kind: ConfigMap
metadata:
  name: config-test
  namespace: default
data:
  SPECIAL_LEVEL: very
  SPECIAL_TYPE: charm

data: the data of the ConfigMap, which is presented as key-value pairs.

Create the configmap-test.yaml file.

# kubectl apply -f configmap-test.yaml
Method 2: Run the kubectl create configmap command
# kubectl create configmap <map-name> <data-source>

# <map-name>: the name of the ConfigMap.
# <data-source>: the data source for creating the ConfigMap, which can be a directory, a file, or left unspecified.

Use a ConfigMap

Method 1: Mount a volume of the ConfigMap type

Sample configmap-volume.yaml file:

apiVersion: v1
kind: Pod
metadata:
   name: pod1-test
spec:
   containers:
     - name: container-test
       image: ksyun/nginx:latest
       volumeMounts:                             # The mount path of the volume.
         - name: config-volume
           mountPath: /etc/config
   volumes:                                      # The pod-specific volumes, which are mounted to containers in the pod.
     - name: config-volume
       configMap:
         name: config-test                       # The name of the ConfigMap mounted.
   restartPolicy: Never
Method 2: Define an environment variable for a container

Sample configmap-env.yaml file:

apiVersion: v1
kind: Pod
metadata:
   name: pod2-test
spec:
   containers:
     - name: container-test
       image: ksyun/nginx:latest
       env:
         - name: SPECIAL_LEVEL_KEY
           valueFrom:
             configMapKeyRef:
               name: config-test                 # The name of the ConfigMap mounted.
               key: SPECIAL_LEVEL               
   restartPolicy: Never
On this page
Pure ModeNormal Mode

Pure Mode

Click to preview the document content in full screen
Feedback