Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tail all logs in a kubernetes cluster

I tried this command:

kubectl logs --tail

I got this error/help output:

Error: flag needs an argument: --tail


Aliases:
logs, log

Examples:
  # Return snapshot logs from pod nginx with only one container
  kubectl logs nginx

  # Return snapshot logs for the pods defined by label app=nginx
  kubectl logs -lapp=nginx

  # Return snapshot of previous terminated ruby container logs from pod web-1
  kubectl logs -p -c ruby web-1

  # Begin streaming the logs of the ruby container in pod web-1
  kubectl logs -f -c ruby web-1

  # 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

  # Return snapshot logs from first container of a job named hello
  kubectl logs job/hello

  # Return snapshot logs from container nginx-1 of a deployment named nginx
  kubectl logs deployment/nginx -c nginx-1

ummm I just want to see all the logs, isn't this a common thing to want to do? How can I tail all the logs for a cluster?

like image 527
Alexander Mills Avatar asked May 03 '19 21:05

Alexander Mills


People also ask

How do I get all the logs from Kubernetes pod?

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 logs of service in Kubernetes?

To do this, you'll have to look at kubelet log. Accessing the logs depends on your Node OS. On some OSes it is a file, such as /var/log/kubelet. log, while other OSes use journalctl to access logs.


1 Answers

If you don't mind using a third party tool, kail does exactly what you're describing.

Streams logs from all containers of all matched pods. [...] With no arguments, kail matches all pods in the cluster.

like image 166
Antoine Cotten Avatar answered Oct 06 '22 09:10

Antoine Cotten