<p>I'm learning Kubernetes and below are the yaml configuration files:
mongo-config.yaml</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: mongo-config
data:
  mongo-url: mongo-service
</code></pre>
<p>mongo-secret.yaml:</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: mongo-secret
type: Opaque
data:
  mongo-user: bW9uZ291c2Vy
  mongo-password: bW9uZ29wYXNzd29yZA==
</code></pre>
<p>mongo.yaml:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-deployment
  labels:
    app: mongo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo
  template:
    metadata:
      labels:
        app: mongo
    spec:
      containers:
      - name: mongodb
        image: mongo:5.0
        ports:
        - containerPort: 27017
        env:
        - name: MONGO_INITDB_ROOT_USERNAME
          valueFrom:
            secretKeyRef:
              name: mongo-secret
              key: mongo-user
        - name: MONGO_INITDB_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mongo-secret
              key: mongo-password
---
apiVersion: v1
kind: Service
metadata:
  name: mongo-service
spec:
  selector:
    app: webapp
  ports:
    - protocol: TCP
      port: 27017
      targetPort: 27017
</code></pre>
<p>webapp.yaml:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: webapp-deployment
  labels:
    app: webapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: webapp
  template:
    metadata:
      labels:
        app: webapp
    spec:
      containers:
      - name: webapp
        image: nanajanashia/k8s-demo-app:v1.0
        ports:
        - containerPort: 3000
        env:
        - name: USER_NAME
          valueFrom:
            secretKeyRef:
              name: mongo-secret
              key: mongo-user
        - name: USER_PWD
          valueFrom:
            secretKeyRef:
              name: mongo-secret
              key: mongo-password
        - name: DB_URL
          valueFrom:
            secretKeyRef:
              name: mongo-config
              key: mongo-url
---
apiVersion: v1
kind: Service
metadata:
  name: webapp-service
spec:
  type: NodePort
  selector:
    app: webapp
  ports:
    - protocol: TCP
      port: 3000
      targetPort: 3000
      nodePort: 30100
</code></pre>
<p>After starting a test webapp i came across the below error:</p>
<pre><code>NAME                                 READY   STATUS                       RESTARTS        AGE
mongo-deployment-7875498c-psn56      1/1     Running                      0               100m
my-go-app-664f7475d4-jgnsk           1/1     Running                      1 (7d20h ago)   7d20h
webapp-deployment-7dc5b857df-6bx4s   0/1     CreateContainerConfigError   0               29m
</code></pre>
<p>which if i try to get more details about the CreateContainerConfigError i get:</p>
<pre><code>~/K8s/K8s-demo$ kubectl describe pod webapp-deployment-7dc5b857df-6bx4s
Name:         webapp-deployment-7dc5b857df-6bx4s
Namespace:    default
Priority:     0
Node:         minikube/192.168.49.2
Start Time:   Thu, 06 Jan 2022 12:20:02 +0200
Labels:       app=webapp
              pod-template-hash=7dc5b857df
Annotations:  &lt;none&gt;
Status:       Pending
IP:           172.17.0.5
IPs:
  IP:           172.17.0.5
Controlled By:  ReplicaSet/webapp-deployment-7dc5b857df
Containers:
  webapp:
    Container ID:   
    Image:          nanajanashia/k8s-demo-app:v1.0
    Image ID:       
    Port:           3000/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CreateContainerConfigError
    Ready:          False
    Restart Count:  0
    Environment:
      USER_NAME:  &lt;set to the key 'mongo-user' in secret 'mongo-secret'&gt;      Optional: false
      USER_PWD:   &lt;set to the key 'mongo-password' in secret 'mongo-secret'&gt;  Optional: false
      DB_URL:     &lt;set to the key 'mongo-url' in secret 'mongo-config'&gt;       Optional: false
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-wkflh (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  kube-api-access-wkflh:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       &lt;nil&gt;
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              &lt;none&gt;
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                  From               Message
  ----     ------     ----                 ----               -------
  Normal   Scheduled  30m                  default-scheduler  Successfully assigned default/webapp-deployment-7dc5b857df-6bx4s to minikube
  Warning  Failed     28m (x12 over 30m)   kubelet            Error: secret &quot;mongo-config&quot; not found
  Normal   Pulled     27s (x142 over 30m)  kubelet            Container image &quot;nanajanashia/k8s-demo-app:v1.0&quot; already present on machine
</code></pre>
<p>which seems that the issue with configuration is:</p>
<pre><code>  Warning  Failed     28m (x12 over 30m)   kubelet            Error: secret &quot;mongo-config&quot; not found
</code></pre>
<p>I don't have a secret with name &quot;mongo-config&quot; but there is a ConfigMap with &quot;mongo-config&quot; name:</p>
<pre><code>&gt;:~/K8s/K8s-demo$ kubectl get secret
NAME                  TYPE                                  DATA   AGE
default-token-gs25h   kubernetes.io/service-account-token   3      5m57s
mongo-secret          Opaque                                2      5m48s
&gt;:~/K8s/K8s-demo$ kubectl get configmap
NAME               DATA   AGE
kube-root-ca.crt   1      6m4s
mongo-config       1      6m4s
</code></pre>
<p>Could you please advice what is the issue here?</p>

ryuken
<p>You have <code>secretKeyRef</code> in:</p>
<pre><code>- name: DB_URL
  valueFrom:
    secretKeyRef:
      name: mongo-config
      key: mongo-url
</code></pre>
<p>You have to use <code>configMapKeyRef</code></p>
<pre><code>    - name: DB_URL
      valueFrom:
        configMapKeyRef:
          name: mongo-config
          key: mongo-url
</code></pre>
