kubectl logs - continuously

9/12/2016
kubectl logs <pod-id>

gets latest logs from my deployment - I am working on a bug and interested to know the logs at runtime - How can I get continuous stream of logs ?

edit: corrected question at the end.

-- npr
google-kubernetes-engine
kubectl
kubernetes

7 Answers

4/4/2020

Try this,

tail logs from pods

kubectl --tail <"no of lines"> logs <"pod_name">

Example :

kubectl --tail 100 logs app_pod

-- Saurabh Bishnoi
Source: StackOverflow

12/12/2019

kubctl logs -f=true [pod-name] -c [container-name]

If you just have a single container over the pod, container name is not necessary else use the container name with -c option. -f i.e. follow is false by default. If you do not set it to true you will get a snapshot of your container logs.

-- Jaraws
Source: StackOverflow

9/12/2016
kubectl logs -f <pod-id>

You can use the -f flag:

-f, --follow=false: Specify if the logs should be streamed.

http://kubernetes.io/docs/user-guide/kubectl/kubectl_logs/

-- Yu-Ju Hong
Source: StackOverflow

9/12/2016

kubectl logs --help will guide you:

Example:

# Begin streaming the logs of the ruby container in pod web-1
kubectl logs -f -c ruby web-1

Flags:

-f, --follow[=false]: Specify if the logs should be streamed.

You can also add --since=10m or so start from that relative time ago.

-- manojlds
Source: StackOverflow

3/29/2018

wait for kubes to spin up pod then move on...

k8s_pod=some_pod
kubectl get pods -w $k8s_pod | while read LOGLINE
do
   [[ "${LOGLINE}" == *"Running"* ]] && pkill -P $ kubectl
done

tail logs

for line in $(kubectl get pods | grep $k8s_pod | awk '{print $1}'); do
    kubectl logs -f $line | tee logfile
done

look for success indicator

tail logfile | grep successful! 
RESULT=$?
exit $RESULT
-- ddtraveller
Source: StackOverflow

4/28/2019

I needed to access the logs of a long running pod, and -f began streaming logs from days ago, which would have taken hours to get to where I needed to view ( just the last couple minutes or so ).

There is a --since=10m flag, but that didn't seem to work for me.

What did wonders was --tail=100, where 100 is the number of recent lines to display.

-- arshbot
Source: StackOverflow

6/14/2019

If you want to get the stream of logs from a multi pod app you can use kubetail, example:

kubectl get pods

NAME                   READY     STATUS    RESTARTS   AGE
app2-v31-9pbpn         1/1       Running   0          1d
app2-v31-q74wg         1/1       Running   0          1d

kubetail app2

With that command, kubetail is tailing the logs from pod app2-v31-9pbpn and app2-v31-q74wg

-- db80
Source: StackOverflow