I'm running a k8s cluster where I have a configmap with a json file in it.
kubectl describe cm my-cmap
Name: my-cmap
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
mydataJson:
----
{
key1 : value1,
key2 : value2
}
Is there a way to get key1 as an ENV variable in a pod ?
You can specify configmap reference in the env section to set environment variables with the values from it. In the pod definition add:
env:
- name: ENV_NAME
valueFrom:
configMapKeyRef:
name: my-cmap
key: key1
If you are interested here you can find another post about "ConfigMap from file" or "ConfigMap from file with environment variables".