Kubernetes Commands
devopskubernetesReferenceBeginner
kubectl logs
Print or stream standard output (stdout) and standard error (stderr) logs from containers running inside a Kubernetes Pod.
Verified: 2026-10-01
Tested on:kubernetes 1.31
Platforms:
all
#kubernetes#kubectl#logs#stdout#debugging
Command
kubectl logs -f deployment/api-server --tail=100
Short Description
kubectl logs retrieves standard output (stdout) and standard error (stderr) streams from containers in a Pod or workload controller.
Syntax
kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER] [FLAGS]Examples
1. Stream Live Logs from a Pod
kubectl logs -f web-app-559d7b489d-abc122. View Logs from the Previous Crashed Container
kubectl logs -p web-app-559d7b489d-abc123. Log a Specific Container in a Multi-Container Pod
kubectl logs web-app-abc12 -c envoy-proxy4. Stream Logs from All Pods Matching a Label
kubectl logs -f -l app=backend-api --all-containers=trueCommon Options
| Option | Shorthand | Description |
|---|---|---|
--follow | -f | Stream logs in real time as they arrive. |
--previous | -p | Print logs for the previously terminated container instance. |
--tail | Lines of recent log file to display (e.g. --tail=50). | |
--since | Show logs written since a duration (e.g. --since=1h or --since=15m). | |
--timestamps | Prefix each log line with an RFC3339 timestamp. |