CreateContainerConfigError: a ConfigMap, Secret or key is missing

Reproduced on k3s v1.31.5 (k3d) with kubectl v1.36.1.

What you see

$ kubectl get pod config-demo -n lab
NAME          READY   STATUS                       RESTARTS   AGE
config-demo   0/1     CreateContainerConfigError   0          2m35s

$ kubectl get events -n lab --field-selector involvedObject.name=config-demo --sort-by=.lastTimestamp
LAST SEEN   TYPE      REASON      OBJECT            MESSAGE
2m32s       Normal    Pulled      pod/config-demo   Successfully pulled image "busybox:1.36" in 3.011s (3.011s including waiting). Image size: 1906887 bytes.
21s         Warning   Failed      pod/config-demo   Error: configmap "app-config" not found

# other variants from the same lab
{"message":"couldn't find key db_host in ConfigMap lab/other-config","reason":"CreateContainerConfigError"}
{"message":"container has runAsNonRoot and image will run as root (pod: \"nonroot-demo_lab(...)\", container: app)","reason":"CreateContainerConfigError"}

What it means

Before starting a container, the kubelet resolves everything the spec points to: env values from ConfigMaps and Secrets, envFrom sources and security settings. If any of that fails, the container waits with CreateContainerConfigError and the runtime is never called.

The image is already pulled at this point. RESTARTS stays at 0. The kubelet keeps retrying, so once you create the missing object the pod starts by itself. In our lab it went to Running without a restart or a redeploy.

A missing ConfigMap or Secret used as a volume behaves differently. That pod stays in ContainerCreating with a FailedMount event instead.

Common causes

The ConfigMap or Secret does not exist

It was never created, was deleted or is applied after the Deployment in your pipeline.

How to tell: The message says configmap "<name>" not found or secret "<name>" not found.

The key is missing

The object exists but the key named in configMapKeyRef or secretKeyRef is not in it. Often a renamed key or a typo.

How to tell: The message says couldn't find key <key> in ConfigMap <namespace>/<name>.

The object is in another namespace

ConfigMaps and Secrets are namespaced. A pod can only read them from its own namespace.

How to tell: kubectl get on the object works with one -n value but not with the pod's namespace.

runAsNonRoot with a root image

The pod requires a non-root user but the image runs as root and no runAsUser is set. The kubelet refuses to start it.

How to tell: The message says container has runAsNonRoot and image will run as root.

How to diagnose it

  1. kubectl get pod <pod> -n <namespace> -o jsonpath='{.status.containerStatuses[*].state.waiting.message}'

    This is the exact reason. It names the missing object or key, or the security rule.

  2. kubectl get events -n <namespace> --field-selector involvedObject.name=<pod> --sort-by=.lastTimestamp

    The Failed events repeat the same message each time the kubelet retries.

  3. kubectl get configmap <name> -n <namespace> -o jsonpath='{.data}'

    Confirm the object exists in this namespace and check the key names. Use kubectl get secret <name> -n <namespace> for Secrets.

  4. kubectl get pod <pod> -n <namespace> -o jsonpath='{.spec.containers[*].env}'

    See every configMapKeyRef and secretKeyRef the pod uses. Check envFrom too with {.spec.containers[*].envFrom}.

How to fix it

Create the missing object or key

Apply the ConfigMap or Secret in the pod's namespace. The waiting pod will start on the kubelet's next retry.

kubectl create configmap <name> -n <namespace> --from-literal=<key>=<value>

Trade-off: Creating it by hand fixes this pod but your manifests are still wrong. Add it to the same source as the Deployment.

Mark the reference optional

Set optional: true on the configMapKeyRef, secretKeyRef or envFrom source if the app can run without it.

env:
- name: DB_HOST
  valueFrom:
    configMapKeyRef:
      name: app-config
      key: db_host
      optional: true

Trade-off: The container starts with the variable unset. If the app needs it, you swap a clear startup error for a confusing runtime one.

Set a non-root user

Add runAsUser with a non-zero UID to the securityContext, or rebuild the image with a USER line.

Trade-off: The app may then fail to write files the image expects to own. Test the image as that user first.

Fix apply order

Make your pipeline or Helm chart create ConfigMaps and Secrets before the workloads that use them.

Trade-off: Needs a change to the deploy tooling. With GitOps tools you may need sync waves or hooks.

How to stop it coming back

  • Keep ConfigMaps and Secrets in the same chart or kustomization as the workload that uses them.
  • Run a pre-deploy check that every referenced ConfigMap, Secret and key exists in the target namespace.
  • When renaming a key, add the new one first and remove the old one only after every consumer moved.

How KubeGraf investigates it

Specialist agents pull the logs, events, metrics, workloads and recent deploys for the failing workload into one view. How KubeGraf handles Kubernetes incidents.

Frequently asked questions

What does configmap not found mean?

The pod reads values from a ConfigMap that does not exist in its namespace. It may never have been created, or it is applied after the Deployment. ConfigMaps are namespaced, so one in another namespace does not count.

What does secret not found mean?

The Secret named in secretKeyRef or envFrom is not in the pod's namespace. Create it there, or mark the reference optional if the app can run without it.

What is the difference between CreateContainerConfigError and CreateContainerError?

CreateContainerConfigError means the kubelet could not build the config, for example because a Secret is missing. CreateContainerError means the container runtime refused to create the container, for example because the image has no command.

Do I need to redeploy after I fix it?

No. The kubelet keeps retrying, so the pod starts once the missing object exists. In our lab it went to Running without a restart or a redeploy.

Last updated . Try KubeGraf Freemium.

Related

Kubernetes documentation