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.
- In a deployment YAML file
- Using Config Map (this article)
- Using Secrets
Config Maps are used to:
- mount configuration files in a container
- create environment variables in a container
- create command line option arguments in a container
Secrets are similar, used to create variables that contain encoded data (e.g. passwords). In this way, if a change is needed to a configuration file, variable, or command line option argument, you just need to update the config map or secret as opposed to having to make the change to your applications or deployments.
The oc get configmaps command will display the config maps in the currently selected project / namespace.
TIP
The -A or --all-namespaces flag can be used to list the config maps in every project / namespace.
The -n or --namespace flag can be used to list the config maps in a certain project / namespace.
~]$ oc get configmaps
NAME DATA AGE
my-config-map 1 44d
The oc describe 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>
Data
====
foo:
----
hello
bar:
----
world
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
data:
foo: hello
bar: world
kind: ConfigMap
metadata:
creationTimestamp: "2021-10-20T10:25:10Z"
managedFields:
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:data:
.: {}
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
The --output jsonpath option can be used to print the value of a specific JSON key.
~]$ oc get configmap my-config-map --output jsonpath={.data.foo}
hello
Did you find this article helpful?
If so, consider buying me a coffee over at