kubernetes

Debugging CreateContainerConfigError vs CreateContainerError in K8s

Debugging CreateContainerConfigError vs CreateContainerError in K8s

By Shubhankar Tripathi • • 5 min read

Learn how to troubleshoot Kubernetes CreateContainerConfigError and CreateContainerError. Fast diagnoses, root causes, and fixes for container startup failures.

Debugging Kubernetes container creation failures can be frustrating—especially when two errors sound almost identical. CreateContainerConfigError and CreateContainerError both indicate that a Pod is stuck before its container ever starts running, but they stem from completely different root causes in the Kubernetes control plane lifecycle.

Understanding the difference between these two states, diagnosing their root causes, and resolving them quickly will keep your workloads running smoothly.

Understanding the Kubernetes Pod Lifecycle Context Before diving into the errors, it helps to understand when they happen. When a Pod is scheduled to a node, the local node agent (kubelet) prepares the pod execution environment before instructing the Container Runtime (like containerd or CRI-O) to start the actual process.

  • CreateContainerConfigError occurs during Step 1: The kubelet fails to prepare or validate the configuration required by the pod specification before even talking to the container runtime.

  • CreateContainerError occurs during Step 2: The configuration is valid, but the container runtime encounters an error when executing the underlying runtime instructions on the host.

Deep Dive: CreateContainerConfigError

This error means Kubernetes could not generate the configuration spec required for the container. The issue almost always lives inside your Pod specification or missing dependent resources.

Top Causes

  1. Missing ConfigMap or Secret: The Pod references a ConfigMap or Secret via envFrom, valueFrom, or volume mounts that does not exist in the active namespace.

  2. Key Mismatch: The Secret or ConfigMap exists, but the exact key referenced under key: inside the Pod YAML is missing or misspelled.

  3. Mounted Volume Path Errors: Attempting to mount a non-existent ConfigMap/Secret as a volume file.

Diagnostic Walkthrough

Check the pod events using kubectl:

>>>>> kubectl describe pod <pod-name> -n <namespace>

Under the Events section, you will see explicit messages highlighting the missing resource:

## Message: Error: key "DB_PASSWORD" not found in secret "db-credentials"

Resolution Strategy

  • Check Resource Existence:

>>>>> kubectl get configmap app-config -n <namespace> 

>>>>> kubectl get secret db-credentials -n <namespace>


  • Verify Key Names: Inspect the keys defined inside the Secret or ConfigMap:
    >>>>> kubectl get secret db-credentials -o jsonpath='{.data}'


Mark Optional Envs: If an environment variable is optional, set optional: true in your Pod specification to prevent the Pod from crashing if the reference is missing:
YAML :
env:

  - name: FEATURE_FLAG

    valueFrom:

      configMapKeyRef:

        name: app-config

        key: feature_flag

        optional: true


Deep Dive: CreateContainerError

This error indicates that Kubernetes successfully prepared the configuration, but the underlying container runtime failed to create the container.

Top Causes

  1. Volume Mount Failures & Permission Denied: Host paths (hostPath) do not exist, or the container's security context prevents mounting or accessing target filesystems.

  2. Device / Port Allocation Conflicts: The requested host port (hostPort) or host device is already bound by another container process on the node.

  3. Invalid Entrypoint / Command Arguments: The executable specified in command: or args: does not exist inside the container image or lacks execute permissions (chmod +x).

  4. Cgroup / Kernel Resource Conflicts: The node has run out of resources (e.g., maximum PID limits, IPC namespace conflicts).

Diagnostic Walkthrough

Run describe pod to get the raw runtime error message:

>>>>> kubectl describe pod <pod-name> -n <namespace>


Typical error outputs look like:

## Error: failed to create containerd task: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/entrypoint.sh": permission denied: unknown

Or a mount failure:

## Error: failed to generate container spec: path "/var/log/app" mounts to host path which does not exist

To dig deeper into host-level runtime issues, inspect the kubelet and containerd logs directly on the node:


# On the affected Kubernetes Node:

>>>>> journalctl -u containerd -n 100 --no-pager

>>>>> journalctl -u kubelet -n 100 --no-pager


Resolution Strategy

Executable Permissions: If using a custom entrypoint script inside your Dockerfile, ensure it has executable rights and a valid shebang line (#!/bin/sh or #!/bin/bash):
DockerFile:
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]


Host Path Verification: If using hostPath mounts, verify that directory exists on the host node or update your volume spec to create missing directories automatically:
YAML :
volumes:

- name: log-dir

  hostPath:

    path: /var/log/app

    type: DirectoryOrCreate


Summary Comparison Table

Feature

CreateContainerConfigError

CreateContainerError

Failure Stage

Kubelet configuration assembly phase

Container Runtime execution phase

Common Origin

K8s API objects (ConfigMap, Secret)

File permissions, Entrypoints, Volumes, Host limits

Container State

Never requested to runtime

Runtime attempted creation and failed

Primary Tool

kubectl describe pod

kubectl describe pod + journalctl -u containerd

Fix Strategy

Validate YAML references & target keys

Fix Dockerfile permissions, volume specs, host ports

Please share and comment to help us improve our content quality and quantity. Let us know for next interesting topic to create a blog on.