kubectl 1.37 reference · Debugging
kubectl logs Command (kubectl)
Print a container's logs from a pod, deployment or job; follow them, limit lines, or read the previous crashed container.
kubectl 1.37
Syntax
kubectl logs POD|TYPE/NAME [-c CONTAINER] [--previous] [-f] [--tail N] [--since 10m]
Parameters
| Parameter | Description |
|---|---|
-c CONTAINER |
Container in a multi-container pod. |
--previous |
Logs of the last terminated container (after a crash). |
-f |
Follow. |
--tail N / --since 10m |
Limit the output. |
-l SELECTOR |
Logs from all pods matching labels. |
Examples
kubectl create namespace rc-ref-logs > /dev/null
trap 'kubectl delete namespace rc-ref-logs --wait=false > /dev/null' EXIT
kubectl -n rc-ref-logs run job1 --restart=Never --image=busybox:1.37 -- sh -c 'for i in 1 2 3; do echo step $i; done' > /dev/null
kubectl -n rc-ref-logs wait --for=jsonpath='{.status.phase}'=Succeeded pod/job1 --timeout=120s > /dev/null
kubectl -n rc-ref-logs logs job1 --tail 2
Output
step 2 step 3
Run this on your computer — see “Get Started” for setup.
kubectl create namespace rc-ref-logs2 > /dev/null
trap 'kubectl delete namespace rc-ref-logs2 --wait=false > /dev/null' EXIT
kubectl -n rc-ref-logs2 create deployment api --image=busybox:1.37 -- sh -c 'echo api started; sleep 3600' > /dev/null
kubectl -n rc-ref-logs2 rollout status deployment/api --timeout=120s > /dev/null; sleep 1
kubectl -n rc-ref-logs2 logs deployment/api
Output
api started
Run this on your computer — see “Get Started” for setup.
Related
kubectl exec· Run a command in a container of a running pod, for example a shell, a database client or a quick check.kubectl describe· Show a detailed, human-readable view of a resource, including related events, the first place to look when debugging.- Troubleshooting Pods · tutorial