title: k8s: configMap does not work in deployment
body: <p>We ran into an issue recently as to using environment variables inside container.</p>
  <p><strong>OS</strong>: windows 10 pro <br/>
  <strong>k8s cluster</strong>: minikube <br/>
  <strong>k8s version</strong>: 1.18.3</p>
  <p><strong>1. The way that doesn't work, though it's preferred way for us</strong></p>
  <p>Here is the deployment.yaml using 'envFrom':</p>
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: db
    labels:
      app.kubernetes.io/name: db
  spec:
    replicas: 1
    selector:
      matchLabels:
        app.kubernetes.io/name: db
    template:
      metadata:
        labels:
          app.kubernetes.io/name: db
      spec:
        serviceAccountName: default
        securityContext:
          {}
        containers:
          - name: db
            image: &quot;postgres:9.4&quot;
            ports:
              - name: http
                containerPort: 5432
                protocol: TCP
            envFrom:
              - configMapRef:
                  name: db-configmap
  </code></pre>
  <p>here is the db.properties:</p>
  <pre><code>POSTGRES_HOST_AUTH_METHOD=trust
  </code></pre>
  <p><em>step 1:</em></p>
  <pre><code>kubectl create configmap db-configmap ./db.properties
  </code></pre>
  <p><em>step 2:</em></p>
  <pre><code>kebuctl apply -f ./deployment.yaml
  </code></pre>
  <p><em>step 3:</em></p>
  <pre><code>kubectl get pod
  </code></pre>
  <p>Run the above command, get the following result:</p>
  <pre><code>db-8d7f7bcb9-7l788        0/1    CrashLoopBackOff   1      9s
  </code></pre>
  <p>That indicates the environment variables POSTGRES_HOST_AUTH_METHOD is <strong>not</strong> injected.</p>
  <p><strong>2. The way that works (we can't work with this approach)</strong></p>
  <p>Here is the deployment.yaml using 'env':</p>
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: db
    labels:
      app.kubernetes.io/name: db
  spec:
    replicas: 1
    selector:
      matchLabels:
        app.kubernetes.io/name: db
    template:
      metadata:
        labels:
          app.kubernetes.io/name: db
      spec:
        serviceAccountName: default
        securityContext:
          {}
        containers:
          - name: db
            image: &quot;postgres:9.4&quot;
            ports:
              - name: http
                containerPort: 5432
                protocol: TCP
            env:
              - name: POSTGRES_HOST_AUTH_METHOD
                value: trust
  </code></pre>
  <p><em>step 1:</em></p>
  <pre><code>kubectl apply -f ./deployment.yaml
  </code></pre>
  <p><em>step 2:</em></p>
  <pre><code>kubectl get pod
  </code></pre>
  <p>Run the above command, get the following result:</p>
  <pre><code>db-fc58f998d-nxgnn                   1/1        Running        0            32s
  </code></pre>
  <p>the above indicates the environment is injected so that the db starts.</p>
  <p>What did I do wrong in the first case?</p>
  <p>Thank you in advance for the help.</p>
  <p><strong>Update:</strong></p>
  <p>Provide the configmap:</p>
  <pre><code> kubectl describe configmap db-configmap
  </code></pre>
  <pre><code>Name:         db-configmap
  Namespace:    default
  Labels:       &lt;none&gt;
  Annotations:  &lt;none&gt;
  
  Data
  ====
  db.properties:
  ----
  POSTGRES_HOST_AUTH_METHOD=trust
  
  </code></pre>