Skip to content
Latchkey

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=100

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →