<p>Hi I am using google kubernetes engine to deploy my application. I tried to add a configMap </p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: configmap
  namespace: default
data:
  database_user: root
  database_password: root
  database_db: db
  database_port: 5432
  database_host: mypostgres
</code></pre>

<p>And then in my application deployment file I mapped my envirement variables like the following</p>

<pre><code> spec:
      containers:
      - env:
        - name: DATABASE_HOST
          valueFrom:
            configMapKeyRef:
              name: configmap
              key: database_host
        - name: DATABASE_NAME
          valueFrom:
            configMapKeyRef:
              name: configmap
              key:  database_db
        - name: DATABASE_PASSWORD
          valueFrom:
            configMapKeyRef:
              name: configmap
              key: database_password
        - name: DATABASE_USER
          valueFrom:
            configMapKeyRef:
              name: configmap
              key: database_user

        - name: DATABASE_PORT
          valueFrom:
            configMapKeyRef:
              name: configmap
              key: database_port
</code></pre>

<p>My service I not running and I got the</p>

<blockquote>
  <p>CreateContainerConfigError 
  When I try to show the result of the pod </p>
</blockquote>

<p>When I do "describe my pod " I got  </p>

<blockquote>
  <p>Error: Couldn't find key database_host</p>
</blockquote>

<p>My question is, why my deployment file are not commincating with the configmap I defined</p>

<p>I created the configmap via this command</p>

<blockquote>
  <p>kubectl create configmap configmap --from-file=configmap.yaml</p>
</blockquote>

Ennar.ch
<p>As mentioned in "kubectl create configmap --help":
--from-env-file='': Specify the path to a file to read lines of key=val pairs to create a configmap (i.e. a Docker
.env file).</p>

<p>so you just need to make a file named conf with value like:</p>

<pre><code>database_user= root
database_password= root
database_db= db
database_port= 5432
database_host= mypostgres
</code></pre>

<p>and run: "kubectl create configmap coco-config --from-env-file=conf"</p>

<p><strong>UPDATE:</strong>
If you put your data in " ", problem will be fixed</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: configmap
  namespace: default
data:
  database_user: "root"
  database_password: "root"
  database_db: "db"
  database_port: "5432"
  database_host: "mypostgres"
</code></pre>
