Skip to main content
In this short guide you’ll find three kubectl commands that frequently speed up debugging and manifest authoring in Kubernetes: 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:
Why this helps:
  • 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.
Illustrative outputs: Previous (crashed) instance:
Current (running) instance:
If your pod has multiple containers, target the container explicitly:
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:
Sample output:
How to interpret common event types:
  • 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).
Use events to determine whether the application crashed on its own or was killed due to failed health checks, resource constraints, or scheduling issues. If you see probe failures, start by reviewing probe config and application startup time.

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:
Typical output (abbreviated):
You can use this information to write correct YAML, for example:
Explore nested fields, container fields, and lists:
Tip: 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 --previous to capture the crash output, then use kubectl get events --sort-by=.metadata.creationTimestamp to see whether Kubernetes killed the pod (e.g., probe failures). If the issue looks like a manifest problem, validate field names and options with kubectl explain.
  • These commands are lightweight, require no additional tooling, and are available in any environment with kubectl configured.

Watch Video