kubectl logs

Fetch logs from containers in Kubernetes pods.

low risk

interactive breakdown — edit the command and press Explain
$ 
What it does

kubectl logs streams container logs from pods. The -c flag targets a specific container in multi-container pods. --previous shows logs from the last terminated container — essential for debugging crashes. -f follows live.

Common flags
FlagMeaning
-f --followStream logs in real time
-c --containerSpecific container in multi-container pod
--previousPrint logs from previously terminated container
--tailLines of recent log to show
--sinceShow logs since duration (e.g., 1h)
-l --selectorStream logs from all pods matching label
Examples
kubectl logs -f mypod -n productionFollow live pod logs · explain & risk-check →
kubectl logs mypod --previousLogs from the crashed previous container · explain & risk-check →
kubectl logs -l app=nginx --all-containers --tail=50Last 50 lines from all nginx pods · explain & risk-check →
kubectl logs deployment/myapp --since=1h | grep ERRORRecent errors from a deployment · explain & risk-check →
Pro tip

Use `kubectl logs --previous` immediately when a pod restarts — the current container starts fresh, and crash logs disappear if you wait too long (especially with short log rotation).

Related
kubectl describe kubectl exec journalctl
Open the full explainer →More in Kubernetes & Helm

Reference text is hand-written and may be incomplete — check man kubectl for your version. Test destructive commands on a non-production system first.