Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailing few lines from huge logs of kubectl logs -f

kubectl logs -f pod shows all logs from the beginning and it becomes a problem when the log is huge and we have to wait for a few minutes to get the last log. Its become more worst when connecting remotely. Is there a way that we can tail the logs for the last 100 lines of logs and follow them?

like image 973
Tinkaal Gogoi Avatar asked Aug 14 '18 06:08

Tinkaal Gogoi


People also ask

How do I search in kubectl logs?

To get Kubectl pod logs, you can access them by adding the -p flag. Kubectl will then get all of the logs stored for the pod. This includes lines that were emitted by containers that were terminated.

How do I get old logs in Kubernetes?

kubectl logs –previous Well, kubectl logs will only show you the logs from a running container. But you can add –previous to the kubectl logs command to see the logs from a previously running container. It's a useful command for debugging purposes.


1 Answers

In a cluster best practices are to gather all logs in a single point through an aggregator and analyze them with a dedicated tool. For that reason in K8S, log command is quite basic.

Anyway kubectl logs -h shows some options useful for you:

# Display only the most recent 20 lines of output in pod nginx kubectl logs --tail=20 nginx  # Show all logs from pod nginx written in the last hour kubectl logs --since=1h nginx 

Some tools with your requirements (and more) are available on github, some of which are:

  • https://github.com/boz/kail

  • https://github.com/wercker/stern

like image 134
Nicola Ben Avatar answered Oct 15 '22 15:10

Nicola Ben