DEV Community

Sedat SALMAN
Sedat SALMAN

Posted on

Pod Stuck in ContainerCreating? 5 Kubernetes Config and Storage Errors Explained and Fixed

Five Pods, and none of them is running. One is Pending, one sits in ContainerCreating, one shows Init:CrashLoopBackOff, and two say CreateContainerConfigError. None of this is a bug in your code. Each of these stops the Pod before your app even starts.

This post follows a Pod from the moment you create it to Running, and fixes the five config and storage problems that block it most often, with real terminal output for each. The video at the top covers the same ground in under four minutes, and each problem has a one-minute Short right where it comes up.

This is part 3 of the series. Part 2 covers Pods that run but can't be reached:

Four gates before Running

Between kubectl apply and Running, a Pod has to pass four gates, in this order:

  1. A node. The scheduler picks one. If the Pod uses a PersistentVolumeClaim, that claim has to be bound first.
  2. Volumes. The kubelet on that node mounts every volume the Pod asks for.
  3. Init containers. They run one at a time, and each has to succeed before the next one starts.
  4. The container environment. The kubelet creates the app containers, with environment variables taken from ConfigMaps and Secrets.

The status tells you which gate stopped the Pod:

  • Pending: no node yet.
  • ContainerCreating for a long time: stuck at the volumes.
  • Init:...: stuck at an init container.
  • CreateContainerConfigError: stuck at the environment.

The routine: status, then events

kubectl get pods gives you the status. Here are all five at once:

$ kubectl get pods
NAME        READY   STATUS                       RESTARTS      AGE
db-client   0/1     CreateContainerConfigError   0             50s
settings    0/1     CreateContainerConfigError   0             50s
shop        0/1     Init:CrashLoopBackOff        4 (18s ago)   50s
web         0/1     ContainerCreating            0             50s
writer      0/1     Pending                      0             50s
Enter fullscreen mode Exit fullscreen mode

Then read the events. kubectl describe pod <name> shows them for one Pod. To see every problem in the namespace at once, filter the events by type:

$ kubectl get events --field-selector type=Warning
LAST SEEN   TYPE      REASON               OBJECT
50s         Warning   FailedScheduling     pod/writer
50s         Warning   FailedMount          pod/web
18s         Warning   Failed               pod/db-client
18s         Warning   BackOff              pod/shop
17s         Warning   Failed               pod/settings
5s          Warning   ProvisioningFailed   persistentvolumeclaim/data
Enter fullscreen mode Exit fullscreen mode

Six warnings, five Pods. Let's take them gate by gate.

1. Pending: the claim isn't bound

writer is Pending, and its events explain why:

$ kubectl describe pod writer | tail -1
  Warning  FailedScheduling  50s  default-scheduler  0/3 nodes are available: pod has unbound immediate PersistentVolumeClaims. preemption: ...
Enter fullscreen mode Exit fullscreen mode

The scheduler won't place a Pod whose claim isn't bound. So the next question is why the claim is stuck:

$ kubectl get pvc data
NAME   STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS
data   Pending                                      fast

$ kubectl describe pvc data | tail -1
  Warning  ProvisioningFailed  5s (x4 over 50s)  ...  storageclass.storage.k8s.io "fast" not found

$ kubectl get storageclass
NAME                 PROVISIONER             RECLAIMPOLICY
standard (default)   rancher.io/local-path   Delete
Enter fullscreen mode Exit fullscreen mode

The claim asks for a storage class called fast, and this cluster only has standard, the default.

A claim's storage class can't be changed after it's created, so patching it won't work. Fix the file, delete the claim and the Pod, and apply again. If you leave storageClassName out, the default class is used.

$ kubectl delete -f data.yaml
persistentvolumeclaim "data" deleted
pod "writer" deleted
$ kubectl apply -f data.yaml
persistentvolumeclaim/data created
pod/writer created

$ kubectl get pvc data
NAME   STATUS   VOLUME                                     CAPACITY
data   Bound    pvc-b4702856-8cd0-429d-9a9a-27a50929697d   1Gi
$ kubectl get pod writer
NAME     READY   STATUS    RESTARTS   AGE
writer   1/1     Running   0          30s
Enter fullscreen mode Exit fullscreen mode

Rule of thumb: Pending with an unbound claim? Check the claim's storage class against kubectl get storageclass.

2. ContainerCreating: a volume can't be mounted

web has been in ContainerCreating for over a minute. That status gives no reason at all. The events do:

$ kubectl describe pod web | tail -1
  Warning  FailedMount  20s (x2 over 80s)  kubelet  MountVolume.SetUp failed for volume "html" : configmap "site-html" not found

$ kubectl get configmaps
NAME               DATA   AGE
app-config         1      80s
kube-root-ca.crt   1      16m
Enter fullscreen mode Exit fullscreen mode

The Pod mounts a ConfigMap called site-html as a volume, and it doesn't exist. A ConfigMap or Secret that you mount as a volume has to exist, unless you mark it optional: true.

The kubelet keeps retrying the mount, so you don't need to touch the Pod. Create the ConfigMap, and it starts by itself:

$ kubectl create configmap site-html --from-file=index.html
configmap/site-html created

$ kubectl get pod web
NAME   READY   STATUS    RESTARTS   AGE
web    1/1     Running   0          110s
Enter fullscreen mode Exit fullscreen mode

Rule of thumb: stuck in ContainerCreating? Read the events. FailedMount usually means a missing ConfigMap or Secret.

3. Init:CrashLoopBackOff: read the init container's logs

shop has an init container called fetch that downloads the page nginx will serve. nginx hasn't started, and it won't until fetch succeeds.

$ kubectl get pod shop
NAME   READY   STATUS                  RESTARTS      AGE
shop   0/1     Init:CrashLoopBackOff   5 (38s ago)   110s
Enter fullscreen mode Exit fullscreen mode

Plain kubectl logs shop targets the app container, which hasn't started yet. Ask for the init container by name with -c:

$ kubectl logs shop -c fetch
wget: bad address 'content'

$ kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   17m
Enter fullscreen mode Exit fullscreen mode

fetch downloads from a Service named content, and there isn't one. Deploy it and expose it:

$ kubectl create deployment content --image=nginx:1.29
deployment.apps/content created
$ kubectl expose deployment content --port=80
service/content exposed

$ kubectl get pod shop
NAME   READY   STATUS    RESTARTS   AGE
shop   1/1     Running   0          2m50s
Enter fullscreen mode Exit fullscreen mode

The kubelet restarts fetch once more, this time it succeeds, and nginx starts.

Rule of thumb: Init:CrashLoopBackOff? Read the init container's logs with -c. The reason is almost always there.

4. CreateContainerConfigError: the ConfigMap name is wrong

settings shows CreateContainerConfigError. The image pulled fine, but the container was never created:

$ kubectl get pods
NAME        READY   STATUS                       ...
settings    0/1     CreateContainerConfigError   ...

$ kubectl describe pod settings | tail -1
  Warning  Failed     17s (x6 over 2m47s)  kubelet  Error: configmap "app-conf" not found
Enter fullscreen mode Exit fullscreen mode

The Pod takes an environment variable from a ConfigMap called app-conf. The ConfigMap we saw earlier is called app-config.

You can't edit the environment of a Pod that already exists. Fix the name in settings.yaml, then replace the Pod:

$ kubectl replace --force -f settings.yaml
pod "settings" deleted
pod/settings replaced

$ kubectl get pod settings
NAME       READY   STATUS    RESTARTS   AGE
settings   1/1     Running   0          20s
$ kubectl exec settings -- printenv APP_MODE
production
Enter fullscreen mode Exit fullscreen mode

If the name is right and it still fails, check the namespace. A Pod can only use ConfigMaps from its own namespace.

Rule of thumb: CreateContainerConfigError? Compare the name in the error with what actually exists.

5. CreateContainerConfigError: the Secret has the wrong key

Same status, different message:

$ kubectl describe pod db-client | tail -1
  Warning  Failed     8s (x7 over 3m8s)  kubelet  Error: couldn't find key password in Secret default/db-pass
Enter fullscreen mode Exit fullscreen mode

The Secret exists, but the Pod asks for a key called password. Describe the Secret. It shows the key names and sizes, never the values:

$ kubectl describe secret db-pass
Name:         db-pass
Namespace:    default
...
Type:  Opaque

Data
====
pass:  11 bytes
Enter fullscreen mode Exit fullscreen mode

The only key is pass. This time the Secret is wrong, not the Pod, so recreate it with the key the Pod expects:

$ kubectl delete secret db-pass
secret "db-pass" deleted
$ kubectl create secret generic db-pass \
    --from-literal=password=Sup3rS3cret
secret/db-pass created

$ kubectl get pod db-client
NAME        READY   STATUS    RESTARTS   AGE
db-client   1/1     Running   0          3m30s
Enter fullscreen mode Exit fullscreen mode

The kubelet keeps retrying on its own, so db-client starts without being touched. On a real cluster, keep passwords out of your shell history: --from-file or your secret manager is a better habit than --from-literal.

Rule of thumb: "couldn't find key"? The name is right. Compare the keys.

Cheat sheet

Status Where to look Usual cause
Pending, "unbound immediate PersistentVolumeClaims" describe pvc, get storageclass The claim's storage class doesn't exist
ContainerCreating for minutes describe pod, Events: FailedMount A ConfigMap or Secret mounted as a volume is missing
Init:CrashLoopBackOff logs <pod> -c <init container> The init container fails, often because something it needs doesn't exist yet
CreateContainerConfigError, "not found" describe pod, get configmaps / get secrets Wrong name, or the object is in another namespace
CreateContainerConfigError, "couldn't find key" describe secret / describe configmap The object exists but the key name differs

Try it yourself

Every terminal output above comes from one session in PodSim, a free, open-source Kubernetes training simulator I'm building. It runs in your browser, so there's no cluster to set up, and each lab checks your fix.

Open sdtslmn.github.io/podsim, go to Labs, and pick:

  • I07 Keep data in a PersistentVolumeClaim
  • I08 Mount configuration files from a ConfigMap
  • I05 Prepare content with an init container
  • B13 Configure a Pod with a ConfigMap
  • B14 Keep a password in a Secret
  • I09 Configure a Pod with a ConfigMap and a Secret

GitHub logo sdtslmn / podsim

PodSim: Kubernetes training simulator. Practice kubectl on a simulated cluster in the browser or terminal, with guided labs.

PodSim

A Kubernetes training simulator. Practice kubectl on a simulated cluster, in your terminal or in the browser, along a training path from your first Pod to real-life production scenarios. Every lab checks your work automatically, and a CKAD track with two timed mock exams prepares you for the certification.

Nothing here runs real containers. The simulator models how Kubernetes objects behave: the scheduler places Pods on nodes, the kubelet pulls images and starts containers, Deployments roll out new ReplicaSets, Services collect endpoints. You see the same states, events and error messages a real cluster gives you, without installing anything or paying for a cluster.

Try it in the browser: https://sdtslmn.github.io/podsim/

The browser version running the Services lab

Why a simulator

Real practice clusters (Killercoda, KodeKloud, kind, minikube) are great once you know the basics. For a first contact they are often too much: you wait for VMs, things break in ways that have nothing to do…




Keep going

Sources


Questions, or a status you keep getting stuck on? Leave a comment.

Kubernetes® is a registered trademark of The Linux Foundation. This post is independent and not affiliated with or endorsed by The Linux Foundation or the CNCF.

Top comments (0)