Stream logs of multiple pods in Kubernetes

What if there are multiple replicas of pod are running and you want to check the logs of all of them simultaneously, of course you can not do kubectl logs to get logs of all the pods That’s what, In this article we will see how we can stream logs of multiple pods in CLI –

Let’s first create a pod – 

Now if I want to stream the logs of this pod, I can run

Ok, That’s easy.
Now, Let’s increase the number of replicas of pod

Now if you want to stream the logs of all the pods, How will you do that?

If you are thinking that, I will just get the logs of deployment but turns out that It only shows the logs of first pod of the Deployment, As you can see here – 

Then, How will you check the logs of all the pods? For this you can use labels.
For that, first find out the labels of your pods

Here you can see there are two app=pinging, pod-template-hash=66dff4b844 labels, these get added automatically when you create a deployment. We will use app=pinging for getting the logs

And, Now stream the logs of all the pods based on this labels

Here you can see the logs of all the pods, though there is a problem as you can not differentiate which line of log belongs to which pod.

We can use Stern for that, Stern allows us to tail multiple pods and multiple containers within pods. Each result is color coded for quicker debugging.

Bonus thing – Let’s increase more replicas of this pod to see one more thing –  

As you can see, You can not stream the logs of more than 5 pods concurrently.

That’s all for now.
Thank you for reading!!

Stay tuned for more articles on Cloud and DevOps. Don’t forget to follow me for regular updates and insights.

Let’s Connect: LinkedIn

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top