Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get logs from all pods of a Kubernetes replication controller?

People also ask

How do you get logs of all pods in Kubernetes?

If you want to show logs of all pods, you can use -l and specify a lable, but at the same time -f won't be used. "but this will choose one pod of the deployment, not all pods" -> true and I've spent a lot of time debugging my app before realizing that not all logs were being displayed.

How do I get logs of multiple pods?

Read Logs Using Kubectl kubectl allows reading logs of a particular pod. It is not possible to get logs from all the pods of a deployment. However, you can use label-selector to get logs from multiple pods. Let's add a label (env=dev) in all the pods and give it a try.

How do I view pods logs?

Checking the logs of a running pod All that you need to do to do that is to run the following command: kubectl logs nginx-7d8b49557c-c2lx9.


You can use labels

kubectl logs -l app=elasticsearch

I've created a small bash script called kubetail that makes this possible. For example to tail all logs for pods named "app1" you can do:

kubetail app1

You can find the script here.


You can get the logs from multiple containers using labels as Adrian Ng suggested:

kubectl logs --selector app=yourappname

In case you have a pod with multiple containers, the above command is going to fail and you'll need to specify the container name:

kubectl logs --selector app=yourappname --container yourcontainername

Note: If you want to see which labels are available to you, the following command will list them all:

kubectl get pod <one of your pods> -o template --template='{{.metadata.labels}}'

...where the output will look something like

map[app:yourappname controller-revision-hash:598302898 pod-template-generation:1]

Note that some of the labels may not be shared by other pods - picking "app" seems like the easiest one


To build on the previous answer if you add -f you can tail the logs.

kubectl logs -f deployment/app