Unlike CrashLoopBackOff, nothing starts and crashes here: the kubelet can't even create the container because something for its configuration is missing. The reason is in the pod's events.
Symptom
k get pods NAME READY STATUS RESTARTS AGE cfg 0/1 CreateContainerConfigError 0 30s
RESTARTS stays at 0: there is no container that could restart.
Diagnosis
The last warning in the pod's events names what is missing.
k describe pod cfg | grep Warning | tail -1
Warning Failed 2s (x5 over 30s) kubelet spec.containers{notes-api}: Error: secret
"notes-key" not found
Causes
secret not foundThe Secret is missing
The pod refers via secretKeyRef to a Secret that doesn't exist in the namespace.
configmap not foundThe ConfigMap is missing or has another name
A typo in the name is enough – k get cm shows what the ConfigMap is really called.
k describe pod -l app=notes | tail -1
k get cm
Warning Failed 6s (x4 over 19s) kubelet spec.containers{notes-api}: Error:
configmap "notes-conf" not found
NAME DATA AGE
kube-root-ca.crt 1 22s
notes-config 1 21scouldn't find keyThe key is missing
The Secret or ConfigMap exists, but the key in the reference has another name.
k get events --field-selector reason=Failed | tail -1 7s Warning Failed pod/broken-5c58d874bc-qjdhv Error: couldn't find key apikey in Secret tag06/notes-key
runAsNonRootNon-root required, image runs as root
Before starting, the kubelet checks which user the image runs as. nginx starts as root – so no start.
k describe pod web | grep -m1 "Error:"
Warning Failed 7s (x3 over 9s) kubelet spec.containers{nginx}: Error: container
has runAsNonRoot and image will run as root (pod: "web_tag08(ef75…)",
container: nginx)Fix
k create secret generic notes-key --from-literal=NOTES_API_KEY=lab-key-123 k get pod cfg secret/notes-key created NAME READY STATUS RESTARTS AGE cfg 1/1 Running 0 3m30s
CKAD hands-on, day 15: reading pod errors, events, logs, ephemeral containers and deprecated APIs.
Go to day 15 →
FAQ
Can I make a reference optional?
Yes. optional true on the reference lets the pod start without the ConfigMap, Secret or key.