RunInitError (Init:RunContainerError) occurs when an init container fails to start or execute. Fix the init container configuration, image, or command before the main containers can run.
RunInitError, shown as Init:RunContainerError in pod status, indicates that an init container failed to start or execute properly. Init containers run sequentially before main application containers, and all init containers must complete successfully before the pod can proceed. This error blocks the entire pod from starting. Unlike main container failures that might trigger restarts, init container failures prevent the pod from ever reaching the Running state until the issue is resolved.
Check init container status:
kubectl describe pod <pod-name>Look at the Init Containers section:
- State: Waiting, Running, or Terminated
- Reason: Why it failed
- Exit Code: 0 (success), 1 (error), 137 (OOMKilled)
Also check:
kubectl get pod <pod-name> -o jsonpath='{.status.initContainerStatuses}'Get logs from the failed init container:
kubectl logs <pod-name> -c <init-container-name>
# If it crashed, get previous logs
kubectl logs <pod-name> -c <init-container-name> --previousThe init container name is defined in your pod spec under initContainers:. Logs reveal the actual error from the container.
Ensure the image exists and command is valid:
# Test the image locally
docker run --rm <init-image> <command>
# Check what command is configured
kubectl get pod <pod-name> -o yaml | grep -A 20 initContainersCommon issues:
- Image tag doesn't exist
- Command path is wrong
- Shell not available in image (use /bin/sh not /bin/bash for alpine)
Init containers MUST complete and exit. They cannot run indefinitely:
# Wrong - runs forever
initContainers:
- name: init
image: busybox
command: ["tail", "-f", "/dev/null"]
# Correct - exits after task
initContainers:
- name: init
image: busybox
command: ["sh", "-c", "until nslookup myservice; do sleep 2; done"]If your init container is meant to wait for something, ensure it has an exit condition.
Exit code 137 means OOMKilled - increase memory:
initContainers:
- name: init-db
image: postgres
resources:
limits:
memory: "256Mi"
requests:
memory: "128Mi"Note: Kubernetes reserves the highest resource request among all init containers (not sum), since they run sequentially.
Init containers often wait for services:
initContainers:
- name: wait-for-db
image: busybox
command: ['sh', '-c', 'until nc -z postgres-service 5432; do echo waiting; sleep 2; done']Check:
- Service exists: kubectl get svc
- DNS resolves: kubectl run test --rm -it --image=busybox -- nslookup <service>
- Port is open: kubectl run test --rm -it --image=busybox -- nc -zv <service> <port>
Init container restart behavior depends on the pod's restartPolicy:
- Always: Kubelet retries using OnFailure behavior
- OnFailure: Kubelet retries the failed init container
- Never: Entire pod marked as failed
For debugging, you can temporarily remove or comment out the init container to see if the main containers work:
# initContainers:
# - name: problematic-init
# ...Common patterns for init containers:
- Wait for a service to be ready
- Clone git repos or download config
- Run database migrations
- Generate configuration files
Each should be idempotent (safe to retry) and have a clear exit condition.
Failed to connect to server: connection refused (HTTP/2)
How to fix "HTTP/2 connection refused" error in Kubernetes
missing request for cpu in container
How to fix "missing request for cpu in container" in Kubernetes HPA
error: invalid configuration
How to fix "error: invalid configuration" in Kubernetes
etcdserver: cluster ID mismatch
How to fix "etcdserver: cluster ID mismatch" in Kubernetes
running with swap on is not supported
How to fix "running with swap on is not supported" in kubeadm