Kubernetes "CreateContainerConfigError": what causes it and how to fix
Fixes Kubernetes CreateContainerConfigError, where a pod spec references a ConfigMap, Secret, or key that does not exist. Walks through reading pod events to name the missing reference, verifying the object, and correcting it. Reach for it when a pod never starts and describe shows the config error.
TL;DR
Run kubectl describe on the stuck pod and read the Events section; the message names the bad reference. It is almost always an env var or envFrom pointing at a missing ConfigMap or Secret key, or a volume referencing a missing object. Create the missing object or fix the reference and the pod starts.
Verbatim error
CreateContainerConfigErrorSteps
- Describe the pod and read the Events tail.
kubectl describe pod [POD] -n [NAMESPACE]Expected: an Event whose message names the missing thing, for example could not find key [KEY] in ConfigMap [NAMESPACE]/[NAME], or configmap [NAME] not found. That message is the fix target.
- Look at the env and envFrom blocks in the pod spec to see every reference.
kubectl get pod [POD] -n [NAMESPACE] -o yamlExpected: you can see which entries use configMapKeyRef, secretKeyRef, or envFrom, so you know which object and key to check.
- Verify the referenced object exists and carries the key.
kubectl get configmap [NAME] -n [NAMESPACE] -o yaml
kubectl get secret [NAME] -n [NAMESPACE] -o yamlExpected: either the object is missing (NotFound) or the key is absent from its data. Recreate the object with the key, or edit the workload to point at the correct name.
- If the event mentions a volume rather than an env var, check the volume source.
kubectl get pvc [PVC-NAME] -n [NAMESPACE]Expected: the PVC exists and is Bound. If it is missing or still Pending, the pod cannot build its config. Fix the volume source, then delete the pod so the controller recreates it.
kubectl delete pod [POD] -n [NAMESPACE]Expected: the replacement pod leaves Pending and moves to Running.
When to use
- A pod is stuck in CreateContainerConfigError after a deploy or config change
- Pod events mention a missing ConfigMap, Secret, key, or downwardAPI field
- The error appeared right after editing env vars, envFrom, or volumes
When not to use
- The pod is in CrashLoopBackOff (the container started, so config was fine)
- The status is ImagePullBackOff (registry or image-name issue, not config)
- The pod is Pending with no container-status message (scheduling or volume-binding issue)
Why it happens
The kubelet assembles the container's runtime config, env vars, files, and mounts, before starting it. If any referenced object or key is absent at that moment, the container can never be created, so it never starts and never restarts. The fix is always at the reference, never in the container image or the app code.
Edge cases
- The Secret exists but the key was renamed: the event names the old key; update the workload or add the key back.
- Marking the reference optional silences the error but leaves the env var unset, which can cause a subtler crash later. Prefer fixing the reference.
- The object exists in the wrong namespace: names must match exactly, and cross-namespace references are not allowed.
- A downwardAPI fieldRef with a misspelled field path produces the same status; check the field path spelling against the pod spec.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_UspyhQgeqvvy3wiyl414BQ