OpenShift - Create Config Map

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

There are different ways to configure a container with environment variables.

config map contains files, variables, and command line options that can be used by one or more applications, as a way to create separation between applications and the files, variables, and command line options being used by the applications.

Or, a secret can be used, so that the data is encoded (not encrypted).

For example, a config map could contain the variable foo=Hello or a secret could contain foo=V29ybGQ= (which is Hello base 64 encoded), and then one or more pods could use the config map or secret to return Hello from the foo key.

With the oc create configmaps command, there are two different command line options that can be used.

  • --from-literal
  • --from-file

Here is an example of how to create a config map using the --from-literal option.

~]$ oc create configmap my-config-map --from-literal foo="Hello" --from-literal bar="World"
configmap/my-config-map created


Let's say you name the file foo.yml and the file contains the following.



And the file named bar.yml contains the following.



Here is how you would create a config map using the --from-file option.

~]# oc create configmap my-config-map --from-file=foo.yml --from-file=bar.yml
configmap/my-config-map created


A JSON or YAML file that contains key value pairs can be used to create a Config Map. These files are known as templates. For example, let's say you have a YAML file named configmap.yml that contains the following markup.

apiVersion: v1
kind: ConfigMap
  name: my-config-map
  namespace: my-project
  foo: hello
  bar: world


The oc apply or oc create command with the -f or --filename option can be used to create the ingress route using the template JSON or YAML file.

The oc replace command can be used to replace an ingress route using a new or updated template JSON or YAML file.

The oc edit command can be used to update an ingress route template YAML file.

~]$ oc apply --filename ingress.yml created


The oc get configmaps command can be used to list the config maps that have been created.

~]$ oc get configmaps
NAME             DATA      AGE
my-config-map    1         30s


The oc descrube configmap command can be used to show the files, variables, and command line options that are defined in the config map.

~]$ oc describe configmap my-config-map
Name:         my-config-map
Namespace:    default
Labels:       <none>
Annotations:  <none>

Events:  <none>


Or, the oc get configmap command with the --output json‚Äč or --output yaml option can be used.

~]$ oc get configmap my-config-map --output yaml
apiVersion: v1
  foo: hello
  bar: world
kind: ConfigMap
  creationTimestamp: "2021-10-20T10:25:10Z"
  - apiVersion: v1
    fieldsType: FieldsV1
        .: {}
        f:key1: {}
        f:key2: {}
    manager: kubectl-create
    operation: Update
    time: "2021-10-20T10:25:10Z"
  name: my-config-map
  namespace: default
  resourceVersion: "104538499"
  selfLink: /api/v1/namespaces/default/configmaps/my-config-map
  uid: 75469a11-949a-4b0d-90f6-adda92cdad49


Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter b9303 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |