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 !!
No comments:
Post a Comment