Kubernetes log location in pod

2020-07-17 06:04发布

I am just trying to find the log location in the pod.

I just logged into the pod as below.

kubectl exec -it POD_NAME bash

But, the logs are not available under /var/logs. Not sure what is the actual log location and how to change that.

Thanks

4条回答
2楼-- · 2020-07-17 06:40

The log file in your containers depend on the application you are running, different applications output logs to different location, for instance, the tomcat in my environment output logs into /usr/local/tomcat/logs directory.

The logs of pod, we mean console output here, will be saved into a container directory in your host, then linked to /var/log/pods/$pod_name directory, you can find logs there.

查看更多
迷人小祖宗
3楼-- · 2020-07-17 06:41

It's impossible to answer your question, because no one other than you knows how your application configured and deployed.

I can only guess your application writes logs to stdout via Docker json logging driver and your logs are stored on the one of your k8s nodes:

$ sudo find /var/lib/docker/containers -name "*-json.log"

By default you can find pod's logs with kubectl -n <namespace> logs <pod_name> command

More info: https://kubernetes.io/docs/concepts/cluster-administration/logging/

查看更多
干净又极端
4楼-- · 2020-07-17 06:41

Please check /opt/logs/app.log

If you are unable to find this directory then just search app.log using find command.

 find / -name "app.log"

In worst case

find / -name "*.log"
查看更多
Luminary・发光体
5楼-- · 2020-07-17 07:00

If your application is writing logs to file, then the location of that log file within the container depends on your application. The location of the log file on the host depends on whether you've mounted the log directory on the host.


If your application is writing logs to stdout, then your container runtime would capture each line and store it on the host. For Docker, this is stored in the /var/lib/docker/containers directory.

But Kubernetes also makes it easier for you to find the log files on the Kubernetes node, by symlinking the relevant log file to /var/log/pods/<namespace>_<pod_name>_<pod_id>/<container_name>/.

查看更多
登录 后发表回答