<p>I have a set of key value pairs in a JSON file that would be mounted in the container. Is there any way to load them directly as environment variables or configmap in Kubernetes directly? I have currently a fallback script to read the file and parse using linux commands, but I am looking for an elegant and/or standard way in Kube to do this. This kube is inside EKS if that is a consideration.</p>
<p>For eg, file;
{key1:value1,key2:value2}</p>
<p>Once done, it should create environment variables like;
echo $key2
value2</p>

manu muraleedharan
<p>You can load the json file into a configMap and then map it to environment variables in your definition file.</p>
<pre><code>kubectl create configmap name-of-your-configmap --from-file=your-file.json
</code></pre>
<p>Then in your yaml definition file:</p>
<pre><code>spec:
  containers:
      ...
      envFrom:
      - configMapRef:
          name: name-of-your-configmap
</code></pre>
