Where are Kubernetes' pods logfiles?

自作多情 提交于 2019-12-03 16:08:36

The on-disk filename comes from

docker inspect $pod_name_or_sha | jq -r '.[0].LogPath'

assuming the docker daemon's configuration is the default {"log-driver": "json-file"}, which is almost guaranteed to be true if kubectl logs behaves correctly.

This may also go without saying, but you must be on the Node upon which the Pod was scheduled for either docker inspect, or sniffing around for the presence of log files on disk, to do anything helpful. kubectl describe pod $pod_name will render the Node name, or as you might suspect it'll be in kubectl get -o json pod $pod_name if you wish to acquire it programmatically.

Do you see anything in those directories?

In my clusters, the stdout/stderr logs from each pod are in /var/log/containers, however there is some linking/redirection:

/var/log/containers/<pod-name>_<namespace>_<container-name-container-id>.log -> /var/log/pods/<some-uuid>/<container-name>_0.log

And that log is actually linked into /var/lib/docker:

<container-name>_0.log -> /var/lib/docker/containers/<container-id>/<container-id>-json.log

Logs are managed by the kubelet on each node. When you run kubectl logs <pod>, it passes the request to the kubelet on the node where your pod is running, and reads the associated logfile.

You can see the architecture here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!