Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

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.

~5 min readKubernetes
#kubernetes#configmap#secrets#troubleshooting
Bold white headline reading CONFIG ERROR with a Kubernetes pod crate blocked at an amber missing key slot beside a cyan secret plate.

Introduction & Quick Summary

A Deployment keeps reporting one pod that never starts:

code
NAME READY STATUS RESTARTS AGE api-7c9f8d6b5-x2k4p 0/1 CreateContainerConfigError 0 3m

Quick 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.

bash
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_KEY
bash
kubectl 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 EventsMeaningFix
secret "x" not foundno Secret with that name in the pod's namespacecreate it, check the namespace
configmap "x" not foundsame for a ConfigMapcreate it before the workload
couldn't find key K in Secret ns/xobject exists, key is missingadd the key or fix the name
couldn't find key K in ConfigMap ns/xsamekubectl get cm x -o yaml
invalid environment variable name "a.b"name violates the POSIX patternuse letters, digits, underscore
secret "x" is not a valid secret nameillegal characters or caselowercase DNS subdomain rules

Key Comparison Table

Reference styleMissing objectMissing keyMissing key allowed
valueFrom.secretKeyReferrorerroronly with optional: true
valueFrom.configMapKeyReferrorerroronly with optional: true
envFrom.secretReferrorkey is skippedoptional: true skips all
envFrom.configMapReferrorkey is skippedoptional: true skips all
Volume mount from Secretpod starts, mount failsfile absentoptional: true mounts empty
env.value literalnot applicablenot applicablealways present

What each status means before you touch a manifest:

StatusContainer startedLogs availableWhere to look
CreateContainerConfigErrornonopod Events, referenced objects
CreateContainerErrornonocontainer runtime errors, entrypoint
ImagePullBackOffnonoregistry auth, image tag
CrashLoopBackOffyes, then exitsyesapplication logs
Pendingnonoscheduling, volumes

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Create the object in the same namespace

bash
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 -d

A 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:

bash
kubectl get pod config-demo -o jsonpath='{.metadata.namespace}'

2. A missing key inside an existing object

bash
kubectl get secret app-secrets -n shop -o json | jq '.data | keys' kubectl get configmap app-config -n shop -o yaml

Keys 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: true

Optional 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:

bash
kubectl rollout restart deployment/api -n shop kubectl rollout status deployment/api -n shop

Volumes 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:

bash
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 documentation

The Kubernetes documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Kubernetes work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Kubernetes guides

More in Kubernetes

All Kubernetes guides

The guides filed next to this one in Kubernetes, in library order.