Configurations Management with ConfigMaps

Configmap is one of the ways to provide configurations to your application.

Injecting env variables with configmaps

Create our configmap for vote app

file: projects/instavote/dev/vote-cm.yaml

apiVersion: v1
kind: ConfigMap
  name: vote
  namespace: instavote
  OPTION_A: Visa
  OPTION_B: Mastercard

In the above given configmap, we define two environment variables,


Lets create the configmap object

oc get cm
oc apply -f vote-cm.yaml
oc get cm
oc describe cm vote

In order to use this configmap in the deployment, we need to reference it from the deployment file.

Check the deployment file for vote add for the following block.

file: vote-dc.yaml

      - image: initcron/oc-vote:v2
        imagePullPolicy: Always
        name: vote
          - configMapRef:
              name: vote
        - containerPort: 80
          protocol: TCP
        restartPolicy: Always

So when you create your deployment, these configurations will be made available to your application. In this example, the values defined in the configmap (Visa and Mastercard) will override the default values(CATS and DOGS) present in your source code.

oc apply -f vote-dc.yaml

Watch the monitoring screen for deployment in progress.

oc get dc --show-labels
oc get rc --show-labels
oc  rollout status dc vote

ConfigMap Dashboard.\label{fig:captioned_image}

Note: Automatic Updation of deployments on ConfigMap Updates

Currently, updating configMap does not ensure a new rollout of a deployment. What this means is even after updading configMaps, pods will not immediately reflect the changes.

There is a feature request for this

Currently, this can be done by using immutable configMaps.

  • Create a configMaps and apply it with deployment.
  • To update, create a new configMaps and do not update the previous one. Treat it as immutable.
  • Update deployment spec to use the new version of the configMaps. This will ensure immediate update.