Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes log - from the beginning

Tags:

kubernetes

I have been running a pod for more than a week and there has been no restart since started. But, still I am unable to view the logs since it started and it only gives logs for the last two days. Is there any log rotation policy for the container and how to control the rotation like based on size or date?

I tried the below command but shows only last two days logs.

kubectl logs POD_NAME --since=0

Is there any other way?

like image 837
user1578872 Avatar asked Jun 15 '18 03:06

user1578872


People also ask

How do I get old logs in Kubernetes?

In case that a pod restarts, and you wanted to check the logs of the previous run, what you need to do is to use the --previous flag: kubectl logs nginx-7d8b49557c-c2lx9 --previous.

How do I get logs of Kubernetes service?

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.

How do I view logs in Kubernetes?

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.


1 Answers

Is there any log rotation policy for the container and how to control the rotation like based on size or date

The log rotation is controlled by the docker --log-driver and --log-opts (or their daemon.json equivalent), which for any sane system has file size and file count limits to prevent a run-away service from blowing out the disk on the docker host. that answer also assumes you are using docker, but that's a fairly safe assumption

Is there any other way?

I strongly advise something like fluentd-elasticsearch, or graylog2, or Sumologic, or Splunk, or whatever in order to egress those logs from the hosts. No serious cluster would rely on infinite log disks nor on using kubectl logs in a for loop to search the output of Pods. To say nothing of egressing the logs from the kubernetes containers themselves, which is almost essential for keeping tabs on the health of the cluster.

like image 136
mdaniel Avatar answered Oct 16 '22 17:10

mdaniel