<p>Given I have created a ConfigMap with a file like that :</p>

<pre><code>VARIABLE1=foo
VARIABLE2=bar
</code></pre>

<p>Is there a way to access those values in Kubernetes or does it have to be in the YAML format?</p>

ZedTuX
<p>Let's say you have a file called <code>z</code> with the contents above. You have two options to make that into a ConfigMap.</p>

<h2>Option 1 (--from-file)</h2>

<pre><code>$ kubectl create cm cm1 --from-file=z
</code></pre>

<p>This will result in an object like this:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: cm1
data:
  z: |
    VARIABLE1=foo
    VARIABLE2=bar
</code></pre>

<p>There is no direct way to project a single value from this ConfigMap as it contains just one blob. However you can, from a shell used in <code>command</code> of a container source that blob (if you project it as a file) and then use the resulting environment variables.</p>

<h2>Option 2 (--from-env-file)</h2>

<pre><code>$ kubectl create cm cm2 --from-env-file=z
</code></pre>

<p>This will result in an object like this:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: cm2
data:
  VARIABLE1: foo
  VARIABLE2: bar
</code></pre>

<p>As you can see the different variables became separate key-value pairs in this case.</p>

<p>There are many more examples in the <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer">reference documentation</a></p>
