Cloud Native 3 min read

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.

Hacker Afternoon Tea
Hacker Afternoon Tea
Hacker Afternoon Tea
Quick Tips for Retrieving Pod Logs with kubectl

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-app

Getting 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>
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

kuberneteskubectltaillabel selectorpod logsfollow
Hacker Afternoon Tea
Written by

Hacker Afternoon Tea

You might find something interesting here ^_^

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.