百度智能云

All Product Document

          Cloud Container Engine

          Configmap Management

          K8S ConfigMap

          ConfigMap is an API object of K8S, which is used to store non-confidential data in key-value pairs. Users can manage ConfigMap through page or kubectl in CCE.

          Manage ConfigMap Through Page

          Create ConfigMap

          Go to "Product Service>Cloud Container Engine CCE->Cluster Details” and click "Configuration Storage>ConfigMap" to enter the ConfigMap list page:

          image.png

          Click "Create ConfigMap” so that the user can create a ConfigMap in the form of YAML. Then, select the cluster and namespace, enter the YAML file, and click "OK" to submit it:

          image.png

          View ConfigMap

          Click the ConfigMap name on any line of the list page so that the ConfigMap details page pops up in the right column:

          image.png

          Delete ConfigMap

          On the ConfigMap list page, check the ConfigMap you want to delete, click the "Delete" button. After confirming the information, click "OK":

          image.png

          Modify the ConfigMap

          On the ConfigMap list page, click the "Edit" button; after completing the modification, click "Update" to submit, and return to the list page after successful submission:

          image.png

          Manage ConfigMap Through kubectl

          Example: ConfigMap

          apiVersion: v1
          kind: ConfigMap
          metadata:
            name: app-config
          data:
            config.json: |
              {
                  "Listener": 9443,
                  "MetricsAddress": "0",
                  "EnableLeaderElection": true,
                  "EnableClusterController": true,
                  "EnableInstanceController": true
              }

          Pod mounts the ConfigMap as a configuration file:

          apiVersion: apps/v1
          kind: Deployment
          metadata:
            name: app-nginx
            labels:
              app: nginx
          spec:
            selector:
              matchLabels:
                app: nginx
            template:
              metadata:
                labels:
                  app: nginx
              spec:
                containers:
                  - name: nginx
                    image: hub.baidubce.com/cce/nginx-alpine-go:latest
                    volumeMounts:
                      - mountPath: /app/conf
                        name: app-config
                volumes:
                  - configMap:
                      defaultMode: 420
                      name: app-config
                    name: app-config

          The file corresponding to the above configmap app-config will be stored in the /app/conf directory of the Pod:

          # exec Enter the container:
          
          $ cat /app/conf/config.json 
          {
              "Listener": 9443,
              "MetricsAddress": "0",
              "EnableLeaderElection": true,
              "EnableClusterController": true,
              "EnableInstanceController": true
          }

          After updating the ConfigMap, the files in the Pod are automatically updated within 1 minute.

          Previous
          Network Management
          Next
          Secret Management