Quick Tips for Retrieving Pod Logs with kubectl
This guide shows how to use kubectl to fetch logs from running Pods (including all replicas), view logs from previously crashed Pods, and retrieve recent or live‑streamed logs using tail and follow options, with commands for label‑based selection and time‑based filtering.
kubectl can be used to retrieve application logs from Pods in a Kubernetes cluster.
First, identify the Pod name or a label that selects the Pods: $ kubectl get pods --show-labels To get logs from a specific Pod: $ kubectl logs <podName> If the Pod has previously crashed, access the logs of the prior instance: $ kubectl logs --previous <podName> When a Pod has multiple replicas and shares a label (e.g., app=my-app), retrieve logs from all Pods with that label:
$ kubectl logs -l app=my-appGetting Recent Logs
The default command returns all logs collected during the Pod's lifetime, which may take time to display. To fetch only the most recent lines, use the --tail flag: $ kubectl logs --tail=100 <podName> To show logs written in the last hour: $ kubectl logs --since=1h <podName> For the last 15 minutes:
kubectl logs --since=15m <podName>Live‑Streaming Logs
To follow logs in real time: $ kubectl logs -f <podName> To follow the most recent 100 lines live:
$ kubectl logs --tail=100 -f <podName>Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
