Skip to content

Instantly share code, notes, and snippets.

@mhausenblas
Last active May 27, 2020 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhausenblas/10e207fcda15bfc281f1ec5641853522 to your computer and use it in GitHub Desktop.
Save mhausenblas/10e207fcda15bfc281f1ec5641853522 to your computer and use it in GitHub Desktop.
ConfigMap data propagation

Does ConfigMap data propagate to pods where it is used?

Experiment

Let's see. We first create a config map called testcm:

kubectl create configmap testcm --from-literal=somekey=INITIAL_VALUE

Now a pod that uses the testcm config map in an environment variable and via a volume mount:

kubectl apply -f podusecm.yaml

Let's have a look at the value of the environment variable created from the config map:

$ kubectl exec -it cmtest -- env | grep SOME_KEY
SOME_KEY=INITIAL_VALUE

And now at the volume mount created from the config map:

$ kubectl exec -it cmtest -- cat /tmp/somekey
INITIAL_VALUE

Now we change the value of the config map data, that is, we assign the somekey key in the testcm config map a new value:

kubectl patch configmap testcm --type merge  -p '{"data":{"somekey":"UPDATED_VALUE"}}'

And check again, first the environment variable:

$ kubectl exec -it cmtest -- env | grep SOME_KEY
SOME_KEY=INITIAL_VALUE

The value of the environment variable SOME_KEY in the pod, which we created from the config map HAS NOT changed.

Finally, we check the volume mount:

$ kubectl exec -it cmtest -- cat /tmp/somekey
UPDATED_VALUE

The value of the file /tmp/somekey in the pod, which we created from the config map HAS changed.

Conclusion

The config map data changes do propagate automatically if used via a volume mount, however not via environmment variables. See also Issue 22368 for details.

apiVersion: v1
kind: Pod
metadata:
name: cmtest
spec:
containers:
- name: main
image: quay.io/mhausenblas/jump:0.2
command: [ "sh", "-c", "sleep 10000" ]
env:
- name: SOME_KEY
valueFrom:
configMapKeyRef:
name: testcm
key: somekey
volumeMounts:
- name: config-volume
mountPath: /tmp
volumes:
- name: config-volume
configMap:
name: testcm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment