<p>I have defined application properties files in a config dir. Config dir is on the below structure.</p>

<pre><code>config
  application.properties
  application-test.properties
  application-dev.properties
  application-prod.properties
</code></pre>

<p>I have defined configmap as below </p>

<pre><code>{{ range $path, $bytes := .Files.Glob "config/*" }}
  {{ base $path }}: '{{- $.Files.Get $path | nindent 2 | upper | replace "." "_" }}'
  {{- end }}
</code></pre>

<p>We are consuming the ConfigMap via environment variables in a running container using the envFrom property. (This in my deployment yaml file)</p>

<pre><code>spec:
   containers:
   - envFrom:
     - configMapRef:
         name: nginx-configmap
</code></pre>

<p>Post running <code>helm install</code>, I see that configmap is generated.</p>

<pre><code>kubectl describe cm sample-configmap
Data
====
----
 SERVER_PORT = 8080 SERVER_NAME = LOCALHOST SERVER_GREETING = GREETING-SERVICE 
----
</code></pre>

<p>In configmap,  the contents are not generated as single string instead of key/value pair.</p>

<p>Even, inside the container, the values are not stored as key/value pair. they are stored as string.</p>

<pre><code>kubectl exec -it &lt;pod&gt; sh
/data # env | grep application.properties
application.properties= SERVER_PORT = 8080 SERVER_NAME = LOCALHOST SERVER_GREETING = GREETING-SERVICE SAMPLE_GROUPA_PARAM1 = VALUE1BASE SAMPLE_GROUPA_PARAM2 = VALUE2BASE SAMPLE_HIGHERPARAM = VALUEHIGHERBASE
/data # echo $application.properties
.properties
/data # echo $SERVER_PORT

</code></pre>

<p>I have also tried </p>

<pre><code>data:
  {{- (.Files.Glob "config/*").AsConfig | nindent 2 | upper | replace "." "_" }}
</code></pre>

<p>observe the same issue. </p>

<p>Is it possible to expose the contents of application.properties as key/value pairs in env inside the container?</p>

Sunil Gajula
<p>The issue is the way you are reading your files and configmap configuration.
Assuming your file from <em>config</em> folder looks like this (please note that integers should be included in as quoted strings):</p>

<p><strong>config.ini</strong></p>

<pre><code>SERVER_PORT = "8080" 
SERVER_NAME = LOCALHOST 
SERVER_GREETING = GREETING-SERVICE 
SAMPLE_GROUPA_PARAM1 = VALUE1BASE 
SAMPLE_GROUPA_PARAM2 = VALUE2BASE 
SAMPLE_HIGHERPARAM = VALUEHIGHERBASE
</code></pre>

<p><strong>configmap.yaml</strong></p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: special-config
data:
{{ range $path, $bytes := .Files.Glob "config/*" }}
  {{- $.Files.Get $path | indent 2 | upper | replace "." "_" | replace " = " ": " }}
{{- end }}
</code></pre>

<p><strong>pod.yaml</strong></p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh", "-c", "env" ]
      envFrom:
      - configMapRef:
          name: special-config
</code></pre>

<p><strong>output:</strong></p>

<pre><code>$ kubectl logs test-pod
KUBERNETES_PORT=tcp://10.96.0.1:443
KUBERNETES_SERVICE_PORT=443
SAMPLE_GROUPA_PARAM1=VALUE1BASE
SAMPLE_GROUPA_PARAM2=VALUE2BASE
HOSTNAME=test-pod
...
PWD=/
KUBERNETES_SERVICE_HOST=10.96.0.1
SERVER_GREETING=GREETING-SERVICE
SERVER_PORT=8080
SERVER_NAME=LOCALHOST
</code></pre>

<p>See <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#configure-all-key-value-pairs-in-a-configmap-as-container-environment-variables" rel="nofollow noreferrer">Configure all key-value pairs in a ConfigMap as container environment variables</a></p>
