I'm having an issue with a Kubernetes pod that uses a ConfigMap. My pod fails to start, with the following error:
Warning Failed 10s (x7 over 2m16s) kubelet, docker-desktop Error: Couldn't find key URL in ConfigMap default/env-config
I created my ConfigMap as follows:
kubectl create configmap env-config --from-file env-config.yaml
This is my ConfigMap:
NAME         DATA   AGE
env-config   1      5m38s
Nates-MacBook-Pro:k8s natereed$ kubectl describe configmap env-config
Name:         env-config
Namespace:    default
Labels:       <none>
Annotations:  <none>
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: <mydb>
  POSTGRESS_HOST: <my host>
  URL: http://localhost:8100  
metadata:
  name: env-configIt 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".
The YAML file looks like this:
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: defaultSo you kind of got things a little weird. What you have there is a config map with one key named env-config.yaml, the value of which is a string containing YAML data for a config map with a bunch of keys including URL. I'm guessing you tried using kubectl create cm --from-file instead of kubectl apply -f?
I'd say that the issue occurred because you are passing a ConfigMap yaml definition as parameter of --from-file.
You could simply create it using: kubectl create -f env-config.yaml
Besides that, if you would like to create using --from-file, then you can define your file only with the parameters that you need, it would be something like:
File name: env-config
AWS_PROFILE: dev
AWS_REGION: us-east-2
JWT_SECRET: foo
POSTGRESS_DB: <mydb>
POSTGRESS_HOST: <my host>
URL: http://localhost:8100And then you can create the ConfigMap in the way you were doing before:
kubectl create configmap env-config --from-file env-config
This would create a ConfigMap like that: (kubectl describe configmap env-config)
Namespace:    default
Labels:       <none>
Annotations:  <none>
Data
====
env-config:
----
AWS_BUCKET: mybucket
AWS_PROFILE: dev
AWS_REGION: us-east-2
JWT_SECRET: foo
POSTGRESS_DB: <mydb>
POSTGRESS_HOST: <my host>
URL: http://localhost:8100
Events:  <none>
Here you can find some useful information: