Kubernetes Logs and Events Cheat Sheet

Find pod logs, previous container logs, event timelines, kube-system logs, and cluster incident evidence quickly.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Pod Logs
Get pod logs
kubectl logs <pod> -n <namespace>

# Print logs from the default container in a pod.

Get logs from a named container
kubectl logs <pod> -n <namespace> -c <container>

# Required for sidecars and multi-container pods.

Follow logs with timestamps
kubectl logs -f <pod> -n <namespace> --timestamps

# Stream logs with timestamps for incident reconstruction.

Tail recent log lines
kubectl logs <pod> -n <namespace> --tail=200

# Limit output while checking current behavior.

Read recent logs only
kubectl logs <pod> -n <namespace> --since=30m

# Filter to a recent time window during an incident.

Read previous logs after a restart
kubectl logs <pod> -n <namespace> --previous

# Useful for restarts and CrashLoopBackOff.

## Aggregate Logs by Workload
Read logs via deployment resource
kubectl logs deployment/<name> -n <namespace>

# Print logs from a workload resource instead of a single pod.

Read logs via Job resource
kubectl logs job/<name> -n <namespace>

# Fetch logs for batch workloads using the Job resource.

Read logs from pods matching a label
kubectl logs -n <namespace> -l app=<label> --all-containers=true --prefix

# Aggregate logs across all containers of pods with a label.

Follow logs for matching pods
kubectl logs -n <namespace> -l app=<label> -f --all-containers=true --max-log-requests=20

# Useful during rollouts or multi-pod incidents.

## Event Analysis
List namespace events
kubectl get events -n <namespace>

# See the recent warning and normal events in a namespace.

Sort events by timestamp
kubectl get events -n <namespace> --sort-by=.metadata.creationTimestamp

# Create an incident timeline from namespace events.

Sort all cluster events by timestamp
kubectl get events -A --sort-by=.metadata.creationTimestamp

# Find cluster-wide warnings around the same time window.

Show warning events only
kubectl get events -A --field-selector type=Warning --sort-by=.metadata.creationTimestamp

# Filter event list down to warning-level entries.

Show events for a specific object
kubectl describe pod <pod> -n <namespace> | sed -n '/Events:/,$p'

# Describe an object and inspect its event section.

## System and Control Plane Logs
Read logs from kube-system pods
kubectl logs -n kube-system -l k8s-app=<label> --all-containers=true --prefix

# Aggregate logs from a system component by label.

List control plane static pods
kubectl get pods -n kube-system -o wide | egrep 'apiserver|scheduler|controller-manager|etcd'

# Check apiserver, scheduler, controller-manager, and etcd pods.

Read kube-apiserver logs
kubectl logs -n kube-system <kube-apiserver-pod>

# Inspect API server errors and admission failures.

Read controller-manager logs
kubectl logs -n kube-system <kube-controller-manager-pod>

# Troubleshoot controllers and reconciliation failures.

Read scheduler logs
kubectl logs -n kube-system <kube-scheduler-pod>

# Inspect placement and scheduling behavior.

## Incident Collection
Export object YAML during incident
kubectl get <resource> <name> -n <namespace> -o yaml > incident-object.yaml

# Capture the exact spec and status for later analysis.

Dump cluster info to a directory
kubectl cluster-info dump --output-directory=./cluster-dump

# Collect cluster state to files instead of stdout.

Save pod logs to a file
kubectl logs <pod> -n <namespace> --all-containers=true > pod.log

# Persist logs for investigation or attachment to a ticket.

Recommended next

No recommendations yet.