kubectl logs --previous (inspect crashed containers), kubectl get events --sort-by=.metadata.creationTimestamp (see recent events chronologically), and kubectl explain (read API docs from the terminal). Each command includes examples and troubleshooting tips so you can apply them quickly.
Quick summary
1) Inspect the previous container’s logs: kubectl logs —previous
When a container fails and Kubernetes launches a replacement (for example during a CrashLoopBackOff),kubectl logs with no extra flags returns logs from the currently running container instance. To retrieve logs from the previous (crashed) instance, add --previous (or -p).
Example: view the previous logs for pod orders-0:
- The previous container often contains the stack trace, startup error, or dependency connection problem that caused the crash.
- Without
--previous, you may only see logs from the fresh instance and miss the root cause.
If you see a CrashLoopBackOff, check
kubectl logs --previous first — it very often contains the immediate cause (stack trace, error connecting to a dependency, or a misconfiguration).2) See recent Kubernetes events in chronological order
kubectl get events surfaces cluster-level events (scheduling decisions, image pulls, probe failures, restarts, etc.). Sorting by the .metadata.creationTimestamp lets you read events in chronological order and correlate them with pod lifecycle actions.
Command:
- Normal / Scheduled, Pulled, Started: lifecycle progress — pod scheduled, image pulled, container started.
- Warning / Unhealthy: probe failures (readiness/liveness) or other issues — often precede a Kubernetes-triggered restart or kill.
- Normal / Killing: Kubernetes terminated the container (for example after failed probes or because it wanted to recreate it).
3) Inspect API docs in the terminal: kubectl explain
kubectl explain prints the server-side documentation for API resources and fields. It’s especially useful while authoring manifests or verifying valid field names and enums without leaving your terminal.
Example: check allowed values for a Deployment strategy type:
kubectl explain reflects the API server version you are connected to, so it matches the fields available in your cluster.
Putting the three together
- When a pod is failing: check
kubectl logs --previousto capture the crash output, then usekubectl get events --sort-by=.metadata.creationTimestampto see whether Kubernetes killed the pod (e.g., probe failures). If the issue looks like a manifest problem, validate field names and options withkubectl explain. - These commands are lightweight, require no additional tooling, and are available in any environment with kubectl configured.