What’s the relationship between deployment and ConfigMap?

I’m curious about how ConfigMap and Deployment works in kubernetes.

I wanted to use the values in ConfigMap as arguments to my deployment pods. I’ve tried this with different images and found different behaviours when passing ConfigMap value as command arguments between containers that use sh as entrypoint and other commands as entrypoint.

Here is an example configuration to better illustrate my case:


apiVersion: v1
kind: ConfigMap
  name: app-envs
  key: "value"
  BUCKET_NAME: "gs://bucket-name/"
  OUTPUT_PATH: "/data"


apiVersion: extensions/v1beta1
kind: Deployment
    - name: firstContainer
      image: busybox
      command: ["sh"]
      - c
      - |
        echo $key
        echo ${BUCKET_NAME}
        echo $(OUTPUT_PATH)
      - configMapRef:
          name: app-envs
    - name: secondContainer
      image: someImage
      args: [ "cmd", "${BUCKET_NAME}", "${OUTPUT_DATA}", "${key}" ] 
      - configMapRef:
          name: app-envs
    - name: thirdContainer
      image: someImage
      args: [ "cmd", "$(BUCKET_NAME)", "$(OUTPUT_DATA)", "$(key)" ] 
      - configMapRef:
          name: app-envs

someImage is a docker image which has certain bash script as its entry point that prints the environment values

The firstContainer and thirdContainer are able to print all the ConfigMap values correctly, meaning, all value, gs://bucket-name/ and /data are received as input arguments.

However, the secondContainer is unable to print these values correctly. I tried to echo the received arguments, and it turned out that it receives ${BUCKET_NAME}, ${OUTPUT_DATA}, and ${key} literally as input arguments instead of the actual values from ConfigMaps.

So after observing the above behaviours, here are my questions:

  1. What’s the relationship between deployment and ConfigMap? Is there
    some kind of order which specify how resources are created in a k8s pod/deployment (eg: whether ConfigMap is loaded first, then the volumeMounts, and then the container, or some kind of orderings)

  2. What’s the difference between ${} and $()? Why does the ConfigMap values are received as literal strings when using ${} to
    a container that has different entrypoint than bash or sh?

Thank you. Your help would be appreciated.

Source: StackOverflow