<p>Creating a new ConfigMap from a file:<br>
<code>kubernetes create configmap foo --from-file=foo</code></p>

<p>This is how the ConfigMap looks internally:
<code>kubernetes get configmaps foo -o yaml</code></p>

<pre><code>apiVersion: v1
data:
  foo: |
    VAR1=value1
    VAR2=value2
</code></pre>

<p>Then, I use this ConfigMap to create a set of environment variables in the container:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  labels:
    name: app
  name: app
spec:
  containers:
    - name: app-server
      image: app:latest
      ports:
        - containerPort: 3000
      envFrom:
      - configMapRef:
          name: foo
      command: ["/bin/bash", "-c", "printenv"]
</code></pre>

<p>When the container command runs, I see the following output for <code>printenv</code>:</p>

<pre><code>foo=VAR1=value1
VAR2=value2
</code></pre>

<p>So, an <code>echo $foo</code> command in the pod returns:<br>
<code>VAR1=value1 VAR2=value2</code></p>

<p>According to the documentation for ConfigMap with <code>--from-file</code>, this is expected behaviour.</p>

<p>What would be a creative way (and the proper place) to somehow get the values of this file available to the pod as individual env variables <code>VAR1</code>, <code>VAR2</code>, <code>VAR3</code>, etc. ?</p>

<p>This is not possible with the current version (1.6.x) of Kubernetes. As written in the <a href="https://kubernetes.io/docs/user-guide/kubectl/v1.6/#-em-configmap-em-" rel="nofollow noreferrer">offical documentation</a> for <code>kubectl create configmap</code>:</p>

<blockquote>
  <p><strong>--from-file:</strong> Key file can be specified using its file path, in which case file basename will be used as configmap key, or optionally with a key and file path, in which case the given key will be used. Specifying a directory will iterate each named file in the directory whose basename is a valid configmap key.</p>
</blockquote>

<p>When you want to create a configmap which is used like this, as input for the <code>envFrom</code> container configuration you could create it with the <code>--from-literal</code> option like this:</p>

<pre><code>kubectl create configmap foo --from-literal=var1=value1 --from-literal=var2=value2
</code></pre>

<p>To still keep the file, you could transform your file into somethings which then runs this command like this:</p>

<pre><code>eval "kubectl create configmap foo $(cat foo.txt | sed -e 's/^/--from-literal=/' | tr "\n" ' ')"
</code></pre>

<p>Along with that maybe checking the outstanding proposals like the <a href="https://github.com/kubernetes/kubernetes/issues/37011" rel="nofollow noreferrer"><code>--flatten</code> flag proposal on Github</a> are worth your time.</p>

<p>Also keep an eye on the variable naming. iirc <code>VAR1</code> and <code>VAR2</code> are not valid property names - they have to be lower case which might cause some issues when passing them on.</p>
