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:
oc create configmap <configmap_name> [options]
$ oc create configmap <configmap_name> [options]Copy to Clipboard Copied! Toggle word wrap Toggle overflow
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:
ls example-files
$ ls example-filesCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
game.properties ui.properties
game.properties ui.propertiesCopy to Clipboard Copied! Toggle word wrap Toggle overflow cat example-files/game.properties
$ cat example-files/game.propertiesCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow cat example-files/ui.properties
$ cat example-files/ui.propertiesCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
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=fairlyNiceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
ConfigMapholding the content of each file in this directory by entering the following command:oc create configmap game-config \ --from-file=example-files/$ oc create configmap game-config \ --from-file=example-files/Copy to Clipboard Copied! Toggle word wrap Toggle overflow When the
--from-fileoption 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:oc describe configmaps game-config
$ oc describe configmaps game-configCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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 describeonly shows the names of the keys and their sizes.Enter the
oc getcommand for the object with the-ooption to see the values of the keys:oc get configmaps game-config -o yaml
$ oc get configmaps game-config -o yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
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
ConfigMapspecifying a specific file: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.propertiesCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the results:
oc get configmaps game-config-2 -o yaml
$ oc get configmaps game-config-2 -o yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
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
ConfigMapspecifying a key-value pair: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.propertiesCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the results:
oc get configmaps game-config-3 -o yaml
$ oc get configmaps game-config-3 -o yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 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
ConfigMapspecifying a literal value: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=charmCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the results:
oc get configmaps special-config -o yaml
$ oc get configmaps special-config -o yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow