Kubernetes: CreateContainerConfigError from a missing key
CreateContainerConfigError means the kubelet could not build the container config. Read the pod Events, then fix the ConfigMap or Secret reference.

Introduction & Quick Summary
A Deployment keeps reporting one pod that never starts:
NAME READY STATUS RESTARTS AGE
api-7c9f8d6b5-x2k4p 0/1 CreateContainerConfigError 0 3mQuick answer: the kubelet could not build the container's configuration. Almost always an environment variable points at a ConfigMap or Secret key that does not exist.
kubectl describe pod api-7c9f8d6b5-x2k4p | sed -n '/Events/,$p'Warning Failed kubelet Error: couldn't find key API_KEY in Secret shop/api-secrets
The pod is scheduled and the image is pulled; the failure happens between those steps and container start, which is why no application log exists. That distinction matters because ImagePullBackOff and CreateContainerConfigError look equally "stuck" in a list but have nothing in common. CreateContainerConfigError is always a reference problem: a missing object, a missing key inside an object, an invalid environment variable name, or a value the runtime cannot accept.
Unlike CrashLoopBackOff, the container never runs, so there are no application logs. The only useful source is the pod's Events and the object the manifest names.
Core Mechanics, Signatures & Reproducible Setup
Reproduce without a cluster dependency:
apiVersion: v1
kind: Pod
metadata:
name: config-demo
spec:
containers:
- name: app
image: busybox:1.36
command: ["sh", "-c", "env; sleep 3600"]
env:
- name: API_KEY
valueFrom:
secretKeyRef:
name: app-secrets
key: API_KEYkubectl apply -f pod.yaml
kubectl get pod config-demo # CreateContainerConfigError
kubectl describe pod config-demo | tail -8
# Error: secret "app-secrets" not found| Failure detail in Events | Meaning | Fix |
|---|---|---|
secret "x" not found | no Secret with that name in the pod's namespace | create it, check the namespace |
configmap "x" not found | same for a ConfigMap | create it before the workload |
couldn't find key K in Secret ns/x | object exists, key is missing | add the key or fix the name |
couldn't find key K in ConfigMap ns/x | same | kubectl get cm x -o yaml |
invalid environment variable name "a.b" | name violates the POSIX pattern | use letters, digits, underscore |
secret "x" is not a valid secret name | illegal characters or case | lowercase DNS subdomain rules |
Key Comparison Table
| Reference style | Missing object | Missing key | Missing key allowed |
|---|---|---|---|
valueFrom.secretKeyRef | error | error | only with optional: true |
valueFrom.configMapKeyRef | error | error | only with optional: true |
envFrom.secretRef | error | key is skipped | optional: true skips all |
envFrom.configMapRef | error | key is skipped | optional: true skips all |
| Volume mount from Secret | pod starts, mount fails | file absent | optional: true mounts empty |
env.value literal | not applicable | not applicable | always present |
What each status means before you touch a manifest:
| Status | Container started | Logs available | Where to look |
|---|---|---|---|
CreateContainerConfigError | no | no | pod Events, referenced objects |
CreateContainerError | no | no | container runtime errors, entrypoint |
ImagePullBackOff | no | no | registry auth, image tag |
CrashLoopBackOff | yes, then exits | yes | application logs |
Pending | no | no | scheduling, volumes |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. Create the object in the same namespace
kubectl create secret generic app-secrets \
--from-literal=API_KEY=dev-key \
--namespace shop
kubectl get secret app-secrets -n shop -o jsonpath='{.data.API_KEY}' | base64 -dA Secret in default is invisible to a pod in shop, and copying manifests between namespaces is the most common cause of a sudden not found after a promotion. Check the namespace on the pod itself:
kubectl get pod config-demo -o jsonpath='{.metadata.namespace}'2. A missing key inside an existing object
kubectl get secret app-secrets -n shop -o json | jq '.data | keys'
kubectl get configmap app-config -n shop -o yamlKeys are case-sensitive, and envFrom treats every key as a variable name, so a key with a dot (app.config) is silently skipped, while secretKeyRef with that same key fails to start the pod. For envFrom, an invalid key is dropped with a warning in the Event; for valueFrom, it is fatal.
3. optional: true where absence is legitimate
env:
- name: FEATURE_FLAGS
valueFrom:
configMapKeyRef:
name: app-config
key: feature-flags
optional: trueOptional references let a pod start before the ConfigMap exists, which is useful for a first deployment. It also hides typos: the variable silently becomes unset. Use it for genuinely optional settings, and keep required credentials non-optional so a missing key fails loudly.
4. Environment variable names the runtime rejects
env:
- name: 2FA_ENABLED # invalid: starts with a digit
value: "true"
- name: app.mode # invalid: dot in a shell environment name
value: "prod"The kubelet validates names against [A-Za-z_][A-Za-z0-9_]* for env. Rename to TWOFA_ENABLED and APP_MODE. A value that must contain a dot belongs in the value, not the name. The same rule applies to keys projected through envFrom, where invalid keys are skipped rather than failing the pod.
5. Secrets change, running pods do not
Editing a Secret does not update the environment of a running container; environment variables are fixed at start. A rollout is required:
kubectl rollout restart deployment/api -n shop
kubectl rollout status deployment/api -n shopVolumes mounted from Secrets do update, with a delay that depends on kubelet sync, so an app that reads a file can pick up a change while an app reading process.env cannot. Treat that difference as part of the design, not a surprise. For a new value that changes a JSON config, check the rendered file with the JSON formatter before rolling out.
6. Ruling out RBAC and image problems
CreateContainerConfigError is raised by the kubelet, which reads Secrets and ConfigMaps with its own credentials; a missing RBAC grant for the pod's ServiceAccount does not cause it. If the Event mentions two reasons at once, fix the first: a pod that cannot build its config never reaches the RBAC checks its application makes. To test a hypothesis without editing the Deployment, run a temporary pod with the same reference:
kubectl run probe -n shop --rm -it --restart=Never \
--image=busybox:1.36 --env="API_KEY=$(kubectl get secret app-secrets -n shop -o jsonpath='{.data.API_KEY}' | base64 -d)" \
-- sh -c 'echo "$API_KEY"'A Secret manifest applied from a file is easier to review as YAML; check indentation and stringData versus data with the YAML validator before applying, because a malformed manifest often applies partially and produces exactly this status.
Common Compilation/Runtime Mistakes & Version Gotchas
Editing the Secret without restarting the Deployment. The pod keeps the old environment and the fix looks ineffective. kubectl rollout restart is the step that applies it.
Assuming envFrom fails on a bad key. It skips invalid keys; only valueFrom is fatal. A missing variable at runtime is often an envFrom skip.
Base64-encoding twice. data: expects base64, stringData: expects plain text. A double-encoded value starts the container and fails authentication later, which looks unrelated to this status.
Creating the Secret in the wrong namespace. Namespaced objects do not cross namespaces, and kubectl get secret without -n shows default.
Deleting a ConfigMap that a running pod mounts. New pods fail with this status while old ones continue, so a rollout stalls at 50%.
Version notes. Kubernetes 1.27 added the --dry-run=server validation path that catches most reference and name errors before apply. Immutable Secrets and ConfigMaps, stable since 1.21, turn an edit into an error rather than a silent update, so a rename-and-recreate is required. kubectl describe output moved Events to the bottom in 1.24, which is why older guides suggest kubectl get events as a fallback.
Reference material: Secrets and Define environment variables for a container.
Official references
primary documentationThe Kubernetes documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Kubernetes work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Kubernetes guides
All Kubernetes guidesKubernetes 1.35: kubelet will not start on a cgroup v1 node
A 1.35 kubelet refuses a cgroup v1 host, and the removed pod-infra flag stops custom images. Check the kernel command line before the node pool.
Kubernetes: x509 certificate has expired or is not yet valid
kubeadm control plane certificates last one year. Renew them, restart the static pods, refresh kubeconfigs, and alert before the next expiry.
kubectl: metadata.resourceVersion: Invalid value: 0x0
The 0x0 error means an update carried no resourceVersion. Switch to apply or patch, or read the live object first, and keep versions out of Git.
no matches for kind in version: removed APIs and missing CRDs
kubectl cannot map the manifest to an endpoint. Either the API version was removed or the CRD is absent, and discovery tells you which.
More in Kubernetes
All Kubernetes guidesThe guides filed next to this one in Kubernetes, in library order.