Course contentsShow
← Cloud and Infrastructure
Lesson 1444 of 2,98929. Kubernetes ObservabilityFree lesson

Troubleshooting with Logs

Using logs to debug pod crashes, restarts, and application errors in Kubernetes.

Troubleshooting with Logs

You'll learn how to use Kubernetes logs to diagnose pod crashes, restarts, and application failures efficiently.

Understanding Log-Based Troubleshooting

When pods crash, restart unexpectedly, or exhibit strange behavior, logs are your primary diagnostic tool. Think of logs as a black box recorder for your containers—they capture what happened right before and during failures, helping you understand why things went wrong.

Common Troubleshooting Scenarios

Pod crashes: Use kubectl logs <pod-name> to view the final messages before termination. If the container has already restarted, add the --previous flag to see logs from the crashed instance: kubectl logs <pod-name> --previous.

Application errors: Look for stack traces, error messages, or unusual patterns. Filter logs by timestamp to correlate issues with deployment or configuration changes.

Container restarts: Check the exit code with kubectl describe pod <pod-name>. An exit code of 137 suggests OOMKilled (out of memory), while 143 indicates termination by signal. Cross-reference this with logs to see memory-related errors.

Multi-container pods: Specify which container's logs you need: kubectl logs <pod-name> -c <container-name>. This is crucial when debugging sidecar configurations or init container failures.

Effective Troubleshooting Workflow

Start broad, then narrow: Check pod status first, examine recent logs, look for patterns across multiple pod replicas, and correlate timestamps with events from kubectl get events. Combine logs with metrics (CPU, memory) and probe failures to build a complete picture.

Key Takeaway: Logs are your time machine for understanding failures—always check previous container logs after crashes, correlate exit codes with log messages, and examine all containers in multi-container pods to pinpoint root causes quickly.