Why does Kubernetes report: "configmap references non-existent config key"?

6/10/2020

In Kubernetes I create a configmap using:

kubectl create configmap dd-agent-config --from-file=./kubernetes/datadog/configmap.yaml

configmap.yaml:

kind: ConfigMap
apiVersion: v1
metadata:
  name: dd-agent-config
  namespace: default
data:
  etcd: |-
    ad_identifiers:
      - etcd
    init_config:
    instances:
      - prometheus_url: "http://%%host%%:2379/metrics"
        ssl_cert: "/etc/kubernetes/pki/etcd/peer.crt"
        ssl_private_key: "/etc/kubernetes/pki/etcd/peer.key"
        ssl_ca_cert: "/etc/kubernetes/pki/etcd/ca.crt"

The description of the configmap loaded in Kubernetes:

$ kubectl describe configmap dd-agent-config               
Name:         dd-agent-config
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
configmap.yaml:
----
kind: ConfigMap
apiVersion: v1
metadata:
  name: dd-agent-config
  namespace: default
data:
  etcd: |-
    ad_identifiers:
      - etcd
    init_config:
    instances:
      - prometheus_url: "http://%%host%%:2379/metrics"
        ssl_cert: "/etc/kubernetes/pki/etcd/peer.crt"
        ssl_private_key: "/etc/kubernetes/pki/etcd/peer.key"
        ssl_ca_cert: "/etc/kubernetes/pki/etcd/ca.crt"
Events:  <none>

My pod definition:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: datadog-agent
spec:
  selector:
    matchLabels:
      app: datadog-agent
  template:
    metadata:
      labels:
        app: datadog-agent
      name: datadog-agent
    spec:
      serviceAccountName: datadog-agent
      containers:
        - image: datadog/agent:7
          name: datadog-agent
          [...]
          volumeMounts:
            - name: confd-config
              mountPath: /conf.d/etcd.d
      volumes:
        - name: confd-config
          configMap:
            name: dd-agent-config
            items:
              - key: etcd
                path: auto_conf.yaml

Somehow this pod is unable to see the configmap key 'etcd':

$ kubectl get events 
0s          Warning   FailedMount         pod/datadog-agent-t56lp                       MountVolume.SetUp failed for volume "confd-config" : configmap references non-existent config key: etcd

and the pod stays in the state of "ContainerCreating"

$ kubectl get pods
NAMESPACE     NAME                                     READY   STATUS              RESTARTS   AGE
default       datadog-agent-t56lp                      0/1     ContainerCreating   0          64s
-- Pascal
configmap
kubernetes
kubernetes-pod

1 Answer

6/10/2020

I found out that the way I created the configmap is wrong.

Instead of creating it like this:

kubectl create configmap dd-agent-config --from-file=./kubernetes/datadog/configmap.yaml

I should have created it like this:

kubectl create -f ./kubernetes/datadog/configmap.yaml

-- Pascal
Source: StackOverflow