-2

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 ?

Dhanuj Dharmarajan
  • 436
  • 1
  • 3
  • 10
  • The Kubernetes documentation has a page on ways to [Configure a Pod to Use a ConfigMap](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/) and it specifically discusses injecting ConfigMap keys as environment variables. – David Maze Jun 02 '19 at 20:13
  • the question is about using a specific key inside a json in configmap – Dhanuj Dharmarajan Jun 09 '19 at 09:51
  • @DhanujDharmarajan - Were you able to overcome this issue? I have to do a similar thing for my config. – Legolas Aug 12 '19 at 20:13
  • @Legolas No. I had to mount the file in container, parse it, and set environment – Dhanuj Dharmarajan Dec 16 '19 at 18:51

2 Answers2

0

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
Ottovsky
  • 2,068
  • 15
  • 22
0

If you are interested here you can find another post about "ConfigMap from file" or "ConfigMap from file with environment variables".

Mark
  • 3,644
  • 6
  • 23