<p>I'm having an issue with a Kubernetes pod that uses a ConfigMap. My pod fails to start, with the following error:</p>

<p><code>Warning  Failed          10s (x7 over 2m16s)  kubelet, docker-desktop  Error: Couldn't find key URL in ConfigMap default/env-config</code></p>

<p>I created my ConfigMap as follows:</p>

<p><code>kubectl create configmap env-config --from-file env-config.yaml</code></p>

<p>This is my ConfigMap:</p>

<pre><code>NAME         DATA   AGE
env-config   1      5m38s
Nates-MacBook-Pro:k8s natereed$ kubectl describe configmap env-config
Name:         env-config
Namespace:    default
Labels:       &lt;none&gt;
Annotations:  &lt;none&gt;

Data
====
env-config.yaml:
----
apiVersion: v1
kind: ConfigMap
data:
  AWS_BUCKET: mybucket
  AWS_PROFILE: dev
  AWS_REGION: us-east-2
  JWT_SECRET: foo
  POSTGRESS_DB: &lt;mydb&gt;
  POSTGRESS_HOST: &lt;my host&gt;
  URL: http://localhost:8100  
metadata:
  name: env-config
</code></pre>

<p>It looks like command to create the ConfigMap is wrong? It's not clear to me why it creates a map with a single key "env-config.yaml".</p>

<p>The YAML file looks like this:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
data:
  AWS_BUCKET: mybucket
  AWS_PROFILE: dev
  AWS_REGION: us-east-2
  JWT_SECRET: foo
  POSTGRESS_DB: mydb
  POSTGRESS_HOST: postgreshost
  URL: http://localhost:8100  
metadata:
  name: env-config
  namespace: default
</code></pre>

Nate Reed
<p>I'd say that the issue occurred because you are passing a ConfigMap yaml definition as parameter of <code>--from-file</code>.</p>

<p>You could simply create it using:
<code>kubectl create -f env-config.yaml</code></p>

<p>Besides that, if you would like to create using <code>--from-file</code>, then you can define your file only with the parameters that you need, it would be something like:</p>

<p>File name: <code>env-config</code></p>

<pre><code>AWS_PROFILE: dev
AWS_REGION: us-east-2
JWT_SECRET: foo
POSTGRESS_DB: &lt;mydb&gt;
POSTGRESS_HOST: &lt;my host&gt;
URL: http://localhost:8100
</code></pre>

<p>And then you can create the ConfigMap in the way you were doing before:</p>

<p><code>kubectl create configmap env-config --from-file env-config</code></p>

<p>This would create a ConfigMap like that: (<code>kubectl describe configmap env-config</code>)</p>

<pre><code>Namespace:    default
Labels:       &lt;none&gt;
Annotations:  &lt;none&gt;

Data
====
env-config:
----
AWS_BUCKET: mybucket
AWS_PROFILE: dev
AWS_REGION: us-east-2
JWT_SECRET: foo
POSTGRESS_DB: &lt;mydb&gt;
POSTGRESS_HOST: &lt;my host&gt;
URL: http://localhost:8100

Events:  &lt;none&gt;
</code></pre>

<p>Here you can find some useful information:</p>

<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#create-configmaps-from-files" rel="noreferrer">Create ConfigMaps from files</a></p>

<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-container-environment-variables-using-configmap-data" rel="noreferrer">Define container environment variables using ConfigMap data</a></p>
