Configuring ConfigMap
Config maps allow you to decouple configuration artifacts from image content to keep containerized applications portable. The following sections define config maps and how to create and use them.
TOC
Understanding Config Maps
Many applications require configuration by using some combination of configuration files, command-line arguments, and environment variables. In OpenShift Container Platform, these configuration artifacts are decoupled from image content to keep containerized applications portable.
The ConfigMap object provides mechanisms to inject containers with configuration data while keeping containers agnostic of OpenShift Container Platform. A config map can be used to store fine-grained information like individual properties or coarse-grained information like entire configuration files or JSON blobs.
The ConfigMap object holds key-value pairs of configuration data that can be consumed in pods or used to store configuration data for system components such as controllers. For example:
Note: You can use the binaryData field when you create a config map from a binary file, such as an image.
Configuration data can be consumed in pods in a variety of ways. A config map can be used to:
- Populate environment variable values in containers
- Set command-line arguments in a container
- Populate configuration files in a volume
Users and system components can store configuration data in a config map. A config map is similar to a secret, but designed to more conveniently support working with strings that do not contain sensitive information.
Config Map Restrictions
- A config map must be created before its contents can be consumed in pods.
- Controllers can be written to tolerate missing configuration data. Consult individual components configured by using config maps on a case-by-case basis.
ConfigMapobjects reside in a project.- They can only be referenced by pods in the same project.
- The Kubectl only supports the use of a config map for pods it gets from the API server. This includes any pods created by using the CLI, or indirectly from a replication controller. It does not include pods created by using the OpenShift Container Platform node's
--manifest-urlflag, its--configflag, or its REST API because these are not common ways to create pods.
A Pod can only use ConfigMaps within the same namespace.
Example ConfigMap
You can now use app-config in a Pod.
Creating a ConfigMap by using the web console
-
Go to Container Platform.
-
In the left sidebar, click Configuration > ConfigMap.
-
Click Create ConfigMap.
-
Refer to the instructions below to configure the relevant parameters.
Example of Bulk Add Format:
-
Click Create.
Creating a ConfigMap by using the CLI
Or from a file:
Operations
You can click the (⋮) on the right side of the list page or click Actions in the upper right corner of the detail page to update or delete the ConfigMap as needed.
Changes to the ConfigMap will affect the workloads that reference the configuration, so please read the operation instructions in advance.
View, Edit and Delete by using the CLI
Ways to Use a ConfigMap in a Pod
As Environment Variables
Each key becomes an environment variable in the container.
As Files in a Volume
Each key is a file under /etc/config, and the file content is the value.