kubectl logs: Command Reference for CI/CD
Read the container output that explains the failure.
kubectl logs prints or follows a container stdout/stderr. The --previous flag, which shows the last crashed instance, is the single most useful option for debugging CrashLoopBackOff in CI. This reference lists the selection and bounding flags.
Common flags and usage
- -f, --follow: stream live output
- -p, --previous: read the prior crashed instance log
- -c <container>: pick a container in a multi-container pod
- --all-containers: concatenate every container log
- --tail=N / --since=10m: bound how much output you fetch
- --timestamps: prefix each line with an RFC3339 timestamp
Example
shell
# On crash, dump the previous instance's log for triage
kubectl logs deploy/web --tail=200 --timestamps || true
kubectl logs my-pod --previous --tail=100In CI
For a pod stuck in CrashLoopBackOff, the current log is often empty because the process died instantly; --previous reads the last crashed instance. Always bound with --tail or --since so a chatty container does not flood the job log.
Key takeaways
- --previous is essential for crash loops: it shows the dead instance.
- Multi-container pods need -c or --all-containers.
- Bound output with --tail/--since so CI logs stay readable.
Related guides
kubectl Cheat Sheet: Commands for Everyday KubernetesA kubectl cheat sheet - get, describe, logs, apply, rollout, debug, and context commands for daily Kubernetes…
kubectl describe: Command Reference for CI/CDReference for kubectl describe: render a resource plus its Events to debug ImagePullBackOff, CrashLoopBackOff…
kubectl exec: Command Reference for CI/CDReference for kubectl exec: run a command inside a running container, the -- separator, container selection,…
kubectl get: Command Reference for CI/CDReference for kubectl get: list resources, output formats, label and field selectors, jsonpath extraction, an…