<p>I have the sample cm.yml for configMap with nested json like data.</p>

<pre><code>kind: ConfigMap
metadata:
 name: sample-cm
data:
 spring: |-
  rabbitmq: |-
   host: "sample.com"
  datasource: |-
   url: "jdbc:postgresql:sampleDb"
</code></pre>

<p>I have to set environment variables, spring-rabbitmq-host=sample.com and spring-datasource-url= jdbc:postgresql:sampleDb in the following pod.</p>

<pre><code>kind: Pod
metadata:
 name: pod-sample
spec:
 containers:
  - name: test-container
    image: gcr.io/google_containers/busybox
    command: [ "/bin/sh", "-c", "env" ]
    env:
     - name: sping-rabbitmq-host
       valueFrom:
        configMapKeyRef:
         name: sample-cm    
         key: &lt;what should i specify here?&gt;
     - name: spring-datasource-url
       valueFrom:
        configMapKeyRef:
         name: sample-cm
         key: &lt;what should i specify here?&gt;
</code></pre>

Sarabesh n.r
<p>Unfortunately it won't be possible to pass values from the configmap you created as separate environment variables because it is read as a single string. </p>

<p>You can check it using <code>kubectl describe cm sample-cm</code></p>

<pre><code>Name:         sample-cm
Namespace:    default
Labels:       &lt;none&gt;
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"v1","data":{"spring":"rabbitmq: |-\n host: \"sample.com\"\ndatasource: |-\n url: \"jdbc:postgresql:sampleDb\""},"kind":"Con...

Data
====
spring:
----
rabbitmq: |-
 host: "sample.com"
datasource: |-
 url: "jdbc:postgresql:sampleDb"
Events:  &lt;none&gt;
</code></pre>

<p>ConfigMap needs key-value pairs so you have to modify it to represent separate values. </p>

<p>Simplest approach would be:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
 name: sample-cm
data:
   host: "sample.com"
   url: "jdbc:postgresql:sampleDb"
</code></pre>

<p>so the values will look like this:</p>

<pre><code>kubectl describe cm sample-cm
Name:         sample-cm
Namespace:    default
Labels:       &lt;none&gt;
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"v1","data":{"host":"sample.com","url":"jdbc:postgresql:sampleDb"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"s...

Data
====
host:
----
sample.com
url:
----
jdbc:postgresql:sampleDb
Events:  &lt;none&gt;
</code></pre>

<p>and pass it to a pod:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
 name: pod
spec:
 containers:
  - name: test-container
    image: gcr.io/google_containers/busybox
    command: [ "/bin/sh", "-c", "env" ]
    env:
    - name: sping-rabbitmq-host
      valueFrom:
        configMapKeyRef:
          name: sample-cm
          key: host
    - name: spring-datasource-url
      valueFrom:
        configMapKeyRef:
          name: sample-cm
          key: url
</code></pre>
