<p>This is my deployment file:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    service: udagram-user
  name: udagram-user
spec:
  replicas: 1
  selector:
    matchLabels:
      service: udagram-user
  template:
    metadata:
      labels:
        service: udagram-user
    spec:
      containers:
      - image: pranjal121997/udagram-user
        name: udagram-user
        imagePullPolicy: Always
        resources:
          requests:
            memory: &quot;64Mi&quot;
            cpu: &quot;250m&quot;
          limits:
            memory: &quot;1024Mi&quot;
            cpu: &quot;500m&quot;
        env:
        - name: POSTGRESS_PASSWORD
          valueFrom:
            configMapKeyRef:
              name: env-config
              key: POSTGRESS_PASSWORD
        - name: POSTGRESS_USERNAME
          valueFrom:
            configMapKeyRef:
              name: env-config
              key: POSTGRESS_USERNAME
        - name: URL
          valueFrom:
            configMapKeyRef:
              name: env-config
              key: URL
        - name: JWT_SECRET
          valueFrom:
            configMapKeyRef:
              name: env-config
              key: JWT_SECRET
        - name: POSTGRESS_DATABASE
          valueFrom:
            configMapKeyRef:
              name: env-config
              key: POSTGRESS_DATABASE
        - name: POSTGRESS_HOST
          valueFrom:
            configMapKeyRef:
              name: env-config
              key: POSTGRESS_HOST
      restartPolicy: Always
</code></pre>
<p>On deploying via kubectl create, it runs into CreateContainerConfigError. Below is the output of kubectl describe pod:</p>
<pre><code>Name:           udagram-user-f57f44889-5jtxf
Namespace:      default
Priority:       0
Node:           ip-172-31-43-242.ap-south-1.compute.internal/172.31.43.242
Start Time:     Wed, 20 May 2020 17:58:34 +0530
Labels:         pod-template-hash=f57f44889
                service=udagram-user
Annotations:    kubernetes.io/psp: eks.privileged
Status:         Pending
IP:             172.31.33.34
Controlled By:  ReplicaSet/udagram-user-f57f44889
Containers:
  udagram-user:
    Container ID:   
    Image:          pranjal121997/udagram-user
    Image ID:       
    Port:           &lt;none&gt;
    Host Port:      &lt;none&gt;
    State:          Waiting
      Reason:       CreateContainerConfigError
    Ready:          False
    Restart Count:  0
    Limits:
      cpu:     500m
      memory:  1Gi
    Requests:
      cpu:     250m
      memory:  64Mi
    Environment:
      POSTGRESS_PASSWORD:  &lt;set to the key 'POSTGRESS_PASSWORD' of config map 'env-config'&gt;  Optional: false
      POSTGRESS_USERNAME:  &lt;set to the key 'POSTGRESS_USERNAME' of config map 'env-config'&gt;  Optional: false
      URL:                 &lt;set to the key 'URL' of config map 'env-config'&gt;                 Optional: false
      JWT_SECRET:          &lt;set to the key 'JWT_SECRET' of config map 'env-config'&gt;          Optional: false
      POSTGRESS_DATABASE:  &lt;set to the key 'POSTGRESS_DATABASE' of config map 'env-config'&gt;  Optional: false
      POSTGRESS_HOST:      &lt;set to the key 'POSTGRESS_HOST' of config map 'env-config'&gt;      Optional: false
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-skqmw (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-skqmw:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-skqmw
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  &lt;none&gt;
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason                  Age                  From                                                   Message
  ----     ------                  ----                 ----                                                   -------
  Normal   Scheduled               3m9s                 default-scheduler                                      Successfully assigned default/udagram-user-f57f44889-5jtxf to ip-172-31-43-242.ap-south-1.compute.internal
  Warning  FailedCreatePodSandBox  3m8s                 kubelet, ip-172-31-43-242.ap-south-1.compute.internal  Failed create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container &quot;93df5832a932be9ad03d0cfd1bbaaae2c44fed0073f1325e02697fd9f6b391e9&quot; network for pod &quot;udagram-user-f57f44889-5jtxf&quot;: NetworkPlugin cni failed to set up pod &quot;udagram-user-f57f44889-5jtxf_default&quot; network: add cmd: failed to assign an IP address to container
  Warning  FailedCreatePodSandBox  3m7s                 kubelet, ip-172-31-43-242.ap-south-1.compute.internal  Failed create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container &quot;ebcf88c3b4d88a19994f6fdd5eee011f257d9e40348f559758e94e7c368da3b2&quot; network for pod &quot;udagram-user-f57f44889-5jtxf&quot;: NetworkPlugin cni failed to set up pod &quot;udagram-user-f57f44889-5jtxf_default&quot; network: add cmd: failed to assign an IP address to container
  Warning  FailedCreatePodSandBox  3m6s                 kubelet, ip-172-31-43-242.ap-south-1.compute.internal  Failed create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container &quot;486dd729e6f9781f7440305cadd0ec6a8eb82129b07efaed2dc1b707c5d03f64&quot; network for pod &quot;udagram-user-f57f44889-5jtxf&quot;: NetworkPlugin cni failed to set up pod &quot;udagram-user-f57f44889-5jtxf_default&quot; network: add cmd: failed to assign an IP address to container
  Warning  FailedCreatePodSandBox  3m5s                 kubelet, ip-172-31-43-242.ap-south-1.compute.internal  Failed create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container &quot;35e39b69cd153b1a9b76b2fc672dec151afb5aebbce5999712891ab6c2329e9f&quot; network for pod &quot;udagram-user-f57f44889-5jtxf&quot;: NetworkPlugin cni failed to set up pod &quot;udagram-user-f57f44889-5jtxf_default&quot; network: add cmd: failed to assign an IP address to container
  Normal   SandboxChanged          3m4s (x4 over 3m7s)  kubelet, ip-172-31-43-242.ap-south-1.compute.internal  Pod sandbox changed, it will be killed and re-created.
  Warning  Failed                  2m9s (x5 over 3m2s)  kubelet, ip-172-31-43-242.ap-south-1.compute.internal  Error: Couldn't find key POSTGRESS_DATABASE in ConfigMap default/env-config
  Normal   Pulling                 114s (x6 over 3m4s)  kubelet, ip-172-31-43-242.ap-south-1.compute.internal  Pulling image &quot;pranjal121997/udagram-user&quot;
  Normal   Pulled                  112s (x6 over 3m2s)  kubelet, ip-172-31-43-242.ap-south-1.compute.internal  Successfully pulled image &quot;pranjal121997/udagram-user&quot;
</code></pre>
<p>I also have 2 other files: aws-secret.yaml and env-secret.yaml containing my postgress username, password and access id's but somehow kubernetes expects all keys to be present in env-configmap.yaml. How do I force my cluster to pick up secrets from the secrets file?</p>

Pranjal Sharma
<p>In the deployment yaml <code>env-config</code> is referred as <code>configMapKeyRef</code> in all the places. Hence kubernetes is expecting <code>POSTGRESS_DATABASE</code> to be present in <code>env-config</code> configMap. You can refer to a secret which contains key <code>POSTGRESS_DATABASE</code> key using <code>secretKeyRef</code>. </p>

<p>Here is an  example.</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: env-single-secret
spec:
  containers:
  - name: envars-test-container
    image: nginx
    env:
    - name: POSTGRESS_DATABASE
      valueFrom:
        secretKeyRef:
          name: postgres-database-secret-name
          key: POSTGRESS_DATABASE
</code></pre>
