Exit code 128 indicates a container startup failure—the runtime could not execute the specified command. Verify the command exists, check for mount issues, or fix invalid exit codes in scripts.
Exit code 128 in Kubernetes indicates that the container runtime failed to start the specified command. This code has two related meanings in Unix systems: First, 128 is the base number for fatal signal exit codes (signal N = exit code 128 + N). Second, exit code 128 alone means "invalid argument to exit" in bash—when a process attempts to exit with a value outside the valid 0-255 range. In Kubernetes, exit code 128 typically appears as ContainerCannotRun, meaning the container failed before the application even started. The command specified in the pod or image doesn't exist, can't be found, or the execution environment isn't properly configured.
Get detailed error information:
kubectl describe pod <pod-name>Look for the Last State section and Events. Common messages include:
- "ContainerCannotRun" - command startup failure
- "StartError: failed to create containerd task" - runtime issue
- "executable file not found in $PATH" - missing binary
Test the image locally:
# Check if command exists
docker run --rm <image>:<tag> which <command>
# List what's in the expected path
docker run --rm <image>:<tag> ls -la /app/
# Try running the exact command
docker run --rm <image>:<tag> <your-command>If the command doesn't exist, fix your Dockerfile to include it.
Exit code 128 can occur when volumes fail to mount:
kubectl describe pod <pod-name> | grep -A 10 "Volumes:"
kubectl get pvc # Check PersistentVolumeClaim statusCommon issues:
- ConfigMap modified while pod is starting
- PVC not bound to a PV
- NFS or cloud storage mount failures
Avoid editing ConfigMaps during pod startup. Use immutable ConfigMaps for critical configs.
If your entrypoint script uses invalid exit values:
# Wrong - exit code must be 0-255
exit 256 # Results in exit code 0
exit -1 # Results in exit code 255
# Correct
exit 1 # Valid error code
exit 0 # SuccessReview your scripts for any dynamic exit codes that might exceed 255.
The container user may lack permission to execute:
securityContext:
runAsUser: 1000
runAsNonRoot: trueEnsure:
1. The binary has execute permissions for that user
2. SecurityContext doesn't block execution
3. No SELinux/AppArmor policies preventing startup
Test locally with the same user:
docker run --user 1000 <image> <command>If the container won't start, override to debug:
command: ["/bin/sh", "-c", "sleep infinity"]Then exec in and investigate:
kubectl exec -it <pod-name> -- /bin/sh
# Check if command exists
which mycommand
ls -la /app/entrypoint.sh
# Try running manually
/app/entrypoint.shExit code 128 from git operations (like npm install with git dependencies) usually indicates SSH key issues. Ensure your container has access to credentials for private repositories.
For ConfigMap race conditions, consider using init containers to wait for configuration to be ready, or use immutable ConfigMaps that don't change after creation.
In multi-stage Docker builds, exit code 128 often indicates the COPY --from stage reference is wrong or the binary wasn't built in the earlier stage. Verify each build stage produces the expected artifacts.
On managed Kubernetes (EKS, GKE, AKS), exit code 128 can also indicate node-level issues like disk pressure or container runtime problems. Check node conditions if multiple pods fail with this code.
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