Cloud Computing guides, explanations and reader checklists on whilenetworking.com

Debugging Kubernetes Pod CrashLoops: Identifying Resource Limits, Liveness Probe Failures, and Image Pull Secrets

When a Kubernetes pod enters a CrashLoopBackOff state, it indicates that the container is starting but immediately exiting. This common failure mode often…

When a Kubernetes pod enters a CrashLoopBackOff state, it indicates that the container is starting but immediately exiting. This common failure mode often stems from misconfigured resource limits, failing health probes, or authentication issues with private container registries. For students and junior engineers working in AWS, Azure, or on-premise clusters, understanding these root causes is essential for maintaining high availability and controlling infrastructure costs.

This guide provides a practical approach to diagnosing these specific failure modes using realistic lab scenarios. We will explore how to inspect logs, analyze event streams, and verify configuration manifests without relying on guesswork. Whether you are setting up an educational sandbox or troubleshooting production workloads, the principles of observing system behavior remain constant.

Inspecting Resource Limits and OOMKills

One of the most frequent causes of crash loops is the container running out of memory. If a pod requests a certain amount of RAM but the system limit is too low, the kernel may terminate the process with an OOMKilled (Out Of Memory) signal, causing the restart loop.

The Scenario

Imagine you are deploying a Python web application on an Azure Kubernetes Service (AKS) cluster. The application has grown in traffic, and users report intermittent timeouts. You suspect the container is being killed by the node’s memory manager.

Step-by-Step Diagnosis

  1. Check the Pod Events: Run kubectl describe pod <pod-name> to view the event history at the bottom of the output. Look for messages containing “OOMKilled”.
  2. Review Resource Requests: Examine the YAML manifest or run kubectl get pod <pod-name> -o yaml. Compare the resources.limits.memory against your node’s capacity.
  3. Adjust Limits: If OOM is confirmed, increase the memory limit. For example:
containers:
- name: app
  image: my-app:v1.2
  resources:
    limits:
      memory: "512Mi"
    requests:
      memory: "256Mi"

Expected Results and Verification

After applying the change, wait for the pod to restart. If the issue was purely resource-related, the pod should transition from CrashLoopBackOff to Running. To verify stability, monitor the container’s memory usage over time using Prometheus or Kubernetes metrics dashboards. Ensure the new limit does not exceed the node’s available RAM, which would cause other pods to be evicted.

Analyzing Liveness Probe Failures

A liveness probe determines if a container is healthy. If the application returns an error code (e.g., HTTP 500) or times out during the probe window, Kubernetes assumes the app is stuck and kills it to free up resources. This results in a crash loop even if the application logic is sound but temporarily slow.

The Scenario

You are managing a microservices architecture on AWS EKS. A new database migration script causes the API service to hang for 30 seconds during startup. Your liveness probe is configured to check the /health endpoint every 10 seconds with a 5-second timeout.

Step-by-Step Diagnosis

  1. Identify Probe Failures: In the kubectl describe pod output, look under the “Events” section for lines stating “Liveness probe failed”.
  2. Check Application Logs: Use kubectl logs <pod-name> -c <container-name> to see if the application is actually responding but returning a bad status code, or if it is simply unresponsive.
  3. Tune Probe Parameters: If the app needs more time to start, increase the initialDelaySeconds or extend the timeoutSeconds.
livenessProbe:
  httpGet:
    path: /health
    port: 8080
  initialDelaySeconds: 60
  periodSeconds: 15
  timeoutSeconds: 3

Common Mistakes and Fixes

A common error is setting failureThreshold too high, which delays restarts, or too low, causing rapid flapping. Another mistake is configuring the probe to hit a path that only returns 200 during normal operation but returns 503 during maintenance. Ensure your application handles probe requests gracefully during startup by returning HTTP 200 or 503 (if configured for readiness) appropriately.

Troubleshooting Image Pull Secrets

When a pod fails to start, the first thing to check is whether the container image can be pulled. If you use private registries like AWS ECR, Azure Container Registry (ACR), or GitHub Packages, missing credentials will prevent the pull, leading to an ImagePullBackOff or immediate exit upon restart attempts.

The Scenario

Your team has migrated to a self-hosted registry on Azure. After updating your deployment manifest to use a new image tag, the pods fail immediately. The status shows ErrImagePull.

Step-by-Step Diagnosis

  1. Verify Image Status: Check if the image exists in the registry using the CLI (e.g., az acr repository show list).
  2. Inspect Pod Events: Look for “unauthorized: authentication required” or “manifest unknown” errors in the pod description.
  3. Validate Secrets: Ensure a Kubernetes secret of type kubernetes.io/dockerconfigjson exists and is mounted correctly to the default service account, or that the specific image pull secret is attached to the namespace.
# Create a secret from an existing Docker credential file
kubectl create secret docker-registry regcred \
  --docker-server=<your-registry-url> \
  --docker-email=<your-email> \
  --from-file=.dockerconfigjson=./auth.json

Security Considerations and Verification

Always ensure that secrets containing registry credentials are rotated regularly. Never hardcode credentials in the Dockerfile or application code. To verify the fix, manually pull the image from a node in the cluster: crictl pull <image-name>. If the manual pull succeeds but the pod does not, check the ServiceAccount annotations to ensure the correct secret is being referenced.

Practical Lab Exercise for Students

To solidify these concepts, students can perform the following lab task in a safe, isolated Kubernetes environment (such as Minikube or Kind):

  1. Setup: Create a simple nginx deployment with insufficient memory limits (e.g., 10MB).
  2. Observation: Watch the pod crash and restart repeatedly.
  3. Fix: Double the memory limit and observe the pod stabilizing.
  4. Probe Test: Modify an application to return a 500 error for the first minute of uptime, then a 200. Configure the liveness probe to trigger after that minute.
  5. Secret Test: Attempt to run a container from a private image without attaching a secret, then attach it and verify the pull succeeds.

Industry Application and Cost Controls

In a production environment, debugging crash loops is not just about fixing errors; it is about cost control and reliability. A pod in CrashLoopBackOff consumes CPU cycles for restart attempts and holds IP addresses or ephemeral storage that could be used by other workloads.

Checklist for Production Troubleshooting

  • [ ] Check kubectl describe pod for OOMKilled events.
  • [ ] Review liveness/readiness probe configurations in the manifest.
  • [ ] Verify image pull secrets are attached to the namespace or service account.
  • [ ] Analyze application logs for unhandled exceptions causing exits.
  • [ ] Confirm node resource availability (not just container limits).

Conclusion

Debugging a crashing Kubernetes pod requires a systematic approach rather than random guessing. By examining resource limits, you prevent memory exhaustion kills. By tuning liveness probes, you avoid premature termination of healthy but slow-starting services. By managing image pull secrets, you ensure secure and reliable deployment from private registries. For students and practitioners alike, mastering these diagnostics ensures robust infrastructure management across AWS, Azure, and other cloud platforms. Always verify assumptions against authoritative documentation and test changes in a non-production environment before applying them to live systems.

Educational-use notice: This tutorial is for learning and controlled lab use only. Test carefully, use backups, and obtain authorization before making changes. Do not run unfamiliar commands on production systems. We accept no responsibility for misuse, damage, data loss, or production issues.