How to fix Exit Code 1 in Kubernetes

KubernetesBEGINNERMEDIUMUpdated Dec 6, 2025· 206 views

Exit code 1 is a generic application error indicating the container process failed. Check container logs for the specific error message and fix the underlying application or configuration issue.

Quick fix

Fixes Exit Code 1

kubectl logs <pod-name>
  1. Check container logs for error messages
  2. Verify environment variables and secrets
  3. Test the container image locally
  4. Check entrypoint and command configuration
kubernetes — error
kubectl logs <pod-name>
Exit Code 1

What this error means

Exit code 1 is a general-purpose error code indicating that a container's main process terminated with a failure. Unlike specific codes like 137 (OOMKilled) or 127 (command not found), exit code 1 is a catch-all that applications use when something goes wrong. This makes exit code 1 both common and challenging to debug—the exit code itself doesn't tell you what failed. The actual cause must be found in container logs, which might show anything from configuration errors to unhandled exceptions to missing dependencies.

Typical symptoms

  • Container terminates immediately or shortly after starting
  • Pod enters CrashLoopBackOff state with exit code 1
  • Deployment rollout stalls waiting for pods to become ready
  • Container logs show error messages before termination
  • Application works locally but fails in Kubernetes
  • Intermittent failures in specific environments
  • Init containers fail with exit code 1 blocking main container

Common causes

  1. Unhandled exception or application crash in code
  2. Missing or invalid environment variables
  3. Configuration file errors or missing config files
  4. Database or external service connection failures
  5. Missing dependencies or incompatible library versions
  6. Invalid command arguments or entrypoint script errors
  7. File permission issues preventing application startup
  8. Missing shebang line in shell script entrypoints

How to fix "Exit Code 1"

1Check container logs for error messages

The logs reveal the actual error:

bash
kubectl logs <pod-name>

For crashed containers, view previous instance logs:

bash
kubectl logs <pod-name> --previous

For multi-container pods:

bash
kubectl logs <pod-name> -c <container-name> --previous

Look for exception stack traces, error messages, or the last operation before termination.

2Verify environment variables and secrets

Missing environment variables are a common cause:

bash
kubectl get pod <pod-name> -o jsonpath='{.spec.containers[0].env}' | jq

Check that referenced secrets and configmaps exist:

bash
kubectl get secrets
kubectl get configmaps

Verify secret values are not empty:

bash
kubectl get secret <secret-name> -o jsonpath='{.data}' | jq
3Test the container image locally

Reproduce the issue outside Kubernetes:

bash
docker run -it <image>:<tag>

If it fails locally, the issue is in the image itself. If it works locally, compare environment differences:
- Environment variables
- Volume mounts
- Network access
- Resource limits

4Check entrypoint and command configuration

Verify the container command is correct:

bash
kubectl get pod <pod-name> -o jsonpath='{.spec.containers[0].command}'
kubectl get pod <pod-name> -o jsonpath='{.spec.containers[0].args}'

Common issues:
- Shell scripts missing shebang line (#!/bin/bash)
- Scripts not marked executable
- Wrong path to entrypoint file

For debugging, override the command temporarily:

yaml
command: ["sleep", "infinity"]

Then exec in and run manually to see real-time errors.

5Verify external service connectivity

If the app connects to databases or APIs on startup:

bash
# Test from a debug pod
kubectl run debug --rm -it --image=busybox -- /bin/sh

# Inside the pod
nslookup <service-name>
nc -zv <host> <port>

Check if services are available and network policies allow access. For databases, verify credentials and connection strings.

6Add verbose logging for debugging

Increase log verbosity to capture more details:

yaml
env:
  - name: LOG_LEVEL
    value: "debug"
  - name: NODE_DEBUG
    value: "*"  # For Node.js

For applications that exit quickly, add startup logging or a delay:

bash
# In entrypoint script
echo "Starting application..."
echo "Environment: $(env)"
exec ./myapp

Advanced notes

Exit code 1 can also result from proper error handling—applications that detect invalid configuration and exit cleanly with code 1 are easier to debug than those that crash unpredictably.

For init containers failing with exit code 1, check that they have all required dependencies. Init containers run before the main container and must complete successfully.

In CI/CD pipelines, exit code 1 failures often indicate environment differences between staging and production. Use kubectl diff to compare manifests and ensure secrets/configmaps match.

When debugging intermittent exit code 1 failures, check if the issue correlates with specific nodes, time of day (load patterns), or after deployments. Race conditions during startup—like connecting to a database before it's ready—can cause sporadic failures that resolve with retry logic or init containers.

Frequently asked questions

What does "Exit Code 1" mean?
Exit code 1 is a general-purpose error code indicating that a container's main process terminated with a failure. Unlike specific codes like 137 (OOMKilled) or 127 (command not found), exit code 1 is a catch-all that applications use when something goes wrong. This makes exit code 1 both common and challenging to debug—the exit code itself doesn't tell you what failed.
How do I fix "Exit Code 1"?
Exit code 1 is a generic application error indicating the container process failed. Check container logs for the specific error message and fix the underlying application or configuration issue.
What causes "Exit Code 1"?
Unhandled exception or application crash in code Missing or invalid environment variables Configuration file errors or missing config files
Is the "Exit Code 1" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading