This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.15.3. Creating a config map
You can use the following command to create a config map from directories, specific files, or literal values.
Procedure
Create a config map:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc create configmap <configmap_name> [options]
$ oc create configmap <configmap_name> [options]
15.3.1. Creating a config map from a directory
You can create a config map from a directory. This method allows you to use multiple files within a directory to create a config map.
Procedure
The following example procedure outlines how to create a config map from a directory.
Start with a directory with some files that already contain the data with which you want to populate a config map:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ls example-files
$ ls example-files
Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow game.properties ui.properties
game.properties ui.properties
Copy to Clipboard Copied! Toggle word wrap Toggle overflow cat example-files/game.properties
$ cat example-files/game.properties
Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow enemies=aliens lives=3 enemies.cheat=true enemies.cheat.level=noGoodRotten secret.code.passphrase=UUDDLRLRBABAS secret.code.allowed=true secret.code.lives=30
enemies=aliens lives=3 enemies.cheat=true enemies.cheat.level=noGoodRotten secret.code.passphrase=UUDDLRLRBABAS secret.code.allowed=true secret.code.lives=30
Copy to Clipboard Copied! Toggle word wrap Toggle overflow cat example-files/ui.properties
$ cat example-files/ui.properties
Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow color.good=purple color.bad=yellow allow.textmode=true how.nice.to.look=fairlyNice
color.good=purple color.bad=yellow allow.textmode=true how.nice.to.look=fairlyNice
Create a
ConfigMap
holding the content of each file in this directory by entering the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc create configmap game-config \ --from-file=example-files/
$ oc create configmap game-config \ --from-file=example-files/
When the
--from-file
option points to a directory, each file directly in that directory is used to populate a key in theConfigMap
, where the name of the key is the file name, and the value of the key is the content of the file.For example, the previous command creates the following
ConfigMap
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc describe configmaps game-config
$ oc describe configmaps game-config
Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Name: game-config Namespace: default Labels: <none> Annotations: <none> Data game.properties: 158 bytes ui.properties: 83 bytes
Name: game-config Namespace: default Labels: <none> Annotations: <none> Data game.properties: 158 bytes ui.properties: 83 bytes
You can see that the two keys in the map are created from the file names in the directory specified in the command. Because the content of those keys might be large, the output of
oc describe
only shows the names of the keys and their sizes.Enter the
oc get
command for the object with the-o
option to see the values of the keys:Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc get configmaps game-config -o yaml
$ oc get configmaps game-config -o yaml
Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow apiVersion: v1 data: game.properties: |- enemies=aliens lives=3 enemies.cheat=true enemies.cheat.level=noGoodRotten secret.code.passphrase=UUDDLRLRBABAS secret.code.allowed=true secret.code.lives=30 ui.properties: | color.good=purple color.bad=yellow allow.textmode=true how.nice.to.look=fairlyNice kind: ConfigMap metadata: creationTimestamp: 2016-02-18T18:34:05Z name: game-config namespace: default resourceVersion: "407"- selflink: /api/v1/namespaces/default/configmaps/game-config uid: 30944725-d66e-11e5-8cd0-68f728db1985
apiVersion: v1 data: game.properties: |- enemies=aliens lives=3 enemies.cheat=true enemies.cheat.level=noGoodRotten secret.code.passphrase=UUDDLRLRBABAS secret.code.allowed=true secret.code.lives=30 ui.properties: | color.good=purple color.bad=yellow allow.textmode=true how.nice.to.look=fairlyNice kind: ConfigMap metadata: creationTimestamp: 2016-02-18T18:34:05Z name: game-config namespace: default resourceVersion: "407"- selflink: /api/v1/namespaces/default/configmaps/game-config uid: 30944725-d66e-11e5-8cd0-68f728db1985
15.3.2. Creating a ConfigMap from a file
You can create a config map from a file.
Procedure
The following example procedure outlines how to create a config map from a file.
If you create a config map from a file, you can include files containing non-UTF8 data that are placed in this field without corrupting the non-UTF8 data. OpenShift Container Platform detects binary files and transparently encodes the file as MIME
. On the server, the MIME
payload is decoded and stored without corrupting the data.
You can pass the --from-file
option multiple times to the CLI. The following example yields equivalent results to the creating from directories example.
Create a
ConfigMap
specifying a specific file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc create configmap game-config-2 \ --from-file=example-files/game.properties \ --from-file=example-files/ui.properties
$ oc create configmap game-config-2 \ --from-file=example-files/game.properties \ --from-file=example-files/ui.properties
Verify the results:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc get configmaps game-config-2 -o yaml
$ oc get configmaps game-config-2 -o yaml
Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow apiVersion: v1 data: game.properties: |- enemies=aliens lives=3 enemies.cheat=true enemies.cheat.level=noGoodRotten secret.code.passphrase=UUDDLRLRBABAS secret.code.allowed=true secret.code.lives=30 ui.properties: | color.good=purple color.bad=yellow allow.textmode=true how.nice.to.look=fairlyNice kind: ConfigMap metadata: creationTimestamp: 2016-02-18T18:52:05Z name: game-config-2 namespace: default resourceVersion: "516" selflink: /api/v1/namespaces/default/configmaps/game-config-2 uid: b4952dc3-d670-11e5-8cd0-68f728db1985
apiVersion: v1 data: game.properties: |- enemies=aliens lives=3 enemies.cheat=true enemies.cheat.level=noGoodRotten secret.code.passphrase=UUDDLRLRBABAS secret.code.allowed=true secret.code.lives=30 ui.properties: | color.good=purple color.bad=yellow allow.textmode=true how.nice.to.look=fairlyNice kind: ConfigMap metadata: creationTimestamp: 2016-02-18T18:52:05Z name: game-config-2 namespace: default resourceVersion: "516" selflink: /api/v1/namespaces/default/configmaps/game-config-2 uid: b4952dc3-d670-11e5-8cd0-68f728db1985
You can specify the key to set in a ConfigMap
for content imported from a file. This can be set by passing a key=value
expression to the --from-file
option. For example:
Create a
ConfigMap
specifying a key-value pair:Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc create configmap game-config-3 \ --from-file=game-special-key=example-files/game.properties
$ oc create configmap game-config-3 \ --from-file=game-special-key=example-files/game.properties
Verify the results:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc get configmaps game-config-3 -o yaml
$ oc get configmaps game-config-3 -o yaml
Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow apiVersion: v1 data: game-special-key: |- enemies=aliens lives=3 enemies.cheat=true enemies.cheat.level=noGoodRotten secret.code.passphrase=UUDDLRLRBABAS secret.code.allowed=true secret.code.lives=30 kind: ConfigMap metadata: creationTimestamp: 2016-02-18T18:54:22Z name: game-config-3 namespace: default resourceVersion: "530" selflink: /api/v1/namespaces/default/configmaps/game-config-3 uid: 05f8da22-d671-11e5-8cd0-68f728db1985
apiVersion: v1 data: game-special-key: |-
1 enemies=aliens lives=3 enemies.cheat=true enemies.cheat.level=noGoodRotten secret.code.passphrase=UUDDLRLRBABAS secret.code.allowed=true secret.code.lives=30 kind: ConfigMap metadata: creationTimestamp: 2016-02-18T18:54:22Z name: game-config-3 namespace: default resourceVersion: "530" selflink: /api/v1/namespaces/default/configmaps/game-config-3 uid: 05f8da22-d671-11e5-8cd0-68f728db1985
- 1
- This is the key that you set in the preceding step.
15.3.3. Creating a config map from literal values
You can supply literal values for a config map.
Procedure
The --from-literal
option takes a key=value
syntax that allows literal values to be supplied directly on the command line.
Create a
ConfigMap
specifying a literal value:Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc create configmap special-config \ --from-literal=special.how=very \ --from-literal=special.type=charm
$ oc create configmap special-config \ --from-literal=special.how=very \ --from-literal=special.type=charm
Verify the results:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc get configmaps special-config -o yaml
$ oc get configmaps special-config -o yaml
Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow apiVersion: v1 data: special.how: very special.type: charm kind: ConfigMap metadata: creationTimestamp: 2016-02-18T19:14:38Z name: special-config namespace: default resourceVersion: "651" selflink: /api/v1/namespaces/default/configmaps/special-config uid: dadce046-d673-11e5-8cd0-68f728db1985
apiVersion: v1 data: special.how: very special.type: charm kind: ConfigMap metadata: creationTimestamp: 2016-02-18T19:14:38Z name: special-config namespace: default resourceVersion: "651" selflink: /api/v1/namespaces/default/configmaps/special-config uid: dadce046-d673-11e5-8cd0-68f728db1985