My scrapbook about almost anything I stumble upon in my tech world. If you find anything useful don't forget to give thumbs-up :)


Friday, March 12, 2021

Get logs from multiple PODs in K8s/Openshift

To get pod or deployment logs is very easy and straight forwards in K8s/Openshift which you can get by running below command - 

$ oc logs <pod_name>
$ kubectl logs <pod_name>

If you want to follow the logs - 

$ oc logs -f <pod_name>
$ kubectl logs -f <pod_name>

But what if you want to get the logs from all the replicas of application for debugging. One way to open N terminal (N = No of replicas) and run the above commands in all the terminal but this is not feasible to monitor if replicas are far greater then 3 or 4. 

With kubectl v1.18, we can follow the logs very easily from multiple pods of an application by running below command - 

$ kubectl logs -f -l app=<app_name>

Let's see this in an example - 

To test this scenario, I have deployed a HTTPD application (Name - hello) with 4 replicas which is listed as below - 

As you are seeing in above screen shot, I have grepped the log for "FOREGR" to avoid the mess on the terminal screen.  

To get logs from all the Pods, I have tried to put all the pods name with kubectl logs command (hit & trial logic) but that is not the right syntax hence the error.  Then, Our command kubectl logs -f -l app=<app_name> comes handy and do the magic. 

Though, Kubectl has provided this functionality but if no of replicas are too high, then this method is get little messy. 
There are few tools, i.e -  Kubetail and Stern available in our disposal to exploit to make our life easy.  So make them useful in your day to day work. 

I'll be back soon.. till then..Happy Learning !! 

Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Telegram Group

No comments:

Post a Comment


The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.