Creating a ConfigMap
Scenario
A ConfigMap is a Kubernetes resource used to store non-sensitive configuration data. Its content is defined by users. After a ConfigMap is created, containerized workloads can use it through volume mounts or environment variable injection.
ConfigMaps decouple configuration files from container images, improving workload portability and preventing unnecessary image rebuilds caused by configuration changes.
The core benefits of ConfigMaps include:
- Easy injection of configuration files into containers: Configuration files can be mounted directly to a specified path in a container, allowing configuration updates without modifying the image.
- Unified management across multiple environments and services: Separate ConfigMaps can be created for different environments (such as development, testing, and production) or different service lines. This enables configuration isolation and efficient management.
- Agile workload deployment and version control: The same workload can be deployed in different environments using different ConfigMaps. ConfigMaps support versioning, enabling efficient workload updates, iterations, and quick rollbacks.
Notes and Constraints
- The size of a ConfigMap resource file cannot exceed 1 MiB.
- ConfigMaps cannot be used in static pods.
Procedure
You can use either of the following ways.
- Log in to the CCE console and click the cluster name to access the cluster console.
- Choose ConfigMaps and Secrets in the navigation pane and click Create ConfigMap in the upper right corner.
- Configure parameters.
Table 1 Parameters for creating a ConfigMap Parameter
Description
Name
Name of the ConfigMap you create, which must be unique in a namespace.
Namespace
Namespace to which the ConfigMap belongs. If you do not specify this parameter, the value default is used by default.
Description
Description of the ConfigMap.
Data
Data of the ConfigMap. Click Add and enter key-value pairs.
- Key: Enter 1 to 63 characters. Only digits, letters, periods (.), hyphens (-), and underscores (_) are allowed. The key cannot start with two periods (..).
- Value: The value can be in string, JSON, or YAML format.
Tag Management (Optional)
Labels of the ConfigMap. Click Add Label and enter key-value pairs. The key and value must contain 1 to 63 characters that start and end with a letter or digit. Only letters, digits, hyphens (-), underscores (_), and periods (.) are allowed.
- Click OK.
The new ConfigMap is displayed in the ConfigMap list.
- Use kubectl to access the cluster. For details, see Accessing a Cluster Using kubectl.
- Create a file named cce-configmap.yaml and edit it.
vi cce-configmap.yaml
File content:
apiVersion: v1 kind: ConfigMap metadata: name: cce-configmap data: SPECIAL_LEVEL: Hello SPECIAL_TYPE: CCE
Table 2 Key parameters Parameter
Description
apiVersion
The value is fixed at v1.
kind
The value is fixed at ConfigMap.
metadata.name
ConfigMap name, which can be customized.
data
ConfigMap data. The value must be key-value pairs.
- Run the following commands to create the ConfigMap:
kubectl create -f cce-configmap.yaml
Run the following commands to view the created ConfigMap:
kubectl get cm
Command output:
NAME DATA AGE cce-configmap 3 7m
Related Operations
|
Operation |
Description |
|---|---|
|
Editing a ConfigMap's YAML file |
Click Edit YAML in the row where the target ConfigMap resides to edit its YAML file. |
|
Updating a ConfigMap |
|
|
Deleting a ConfigMap |
Select the target ConfigMap and choose . Delete the ConfigMap as instructed. |
|
Rolling back a ConfigMap |
Select the target ConfigMap and choose to roll back it to the specified historical version as instructed. This function is available only when the ConfigMap has a historical version. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot