Many applications require configuration using some combination of configuration files, command line arguments, and environment variables. In OpenShift Container Platform, these configuration artifacts are decoupled from image content in order 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 ConfigMap can be used to store fine-grained information like individual properties or coarse-grained information like entire configuration files or JSON blobs.
The ConfigMap API 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:
ConfigMap Object Definition
kind: ConfigMap
apiVersion: v1
metadata:
creationTimestamp: 2016-02-18T19:14:38Z
name: example-config
namespace: default
data: (1)
example.property.1: hello
example.property.2: world
example.property.file: |-
property.1=value-1
property.2=value-2
property.3=value-3
binaryData:
bar: L3Jvb3QvMTAw (2)
1 |
Contains the configuration data. |
2 |
Points to a file that contains non-UTF8 data, for example, a binary Java keystore file. Enter the file data in Base 64. |
|
You can use the binaryData field when you create a ConfigMap from a binary file, such as an image.
|
Configuration data can be consumed in Pods in a variety of ways. A ConfigMap 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 ConfigMap.
A ConfigMap is similar to a secret, but designed to more conveniently support working with strings that do not contain sensitive information.
ConfigMap restrictions
A ConfigMap 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 ConfigMaps on a case-by-case basis.
ConfigMap objects reside in a project.
They can only be referenced by Pods in the same project.
The Kubelet only supports the use of a ConfigMap 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-url
flag, its --config
flag, or its REST API because these are not common ways to create Pods.