what is the absolute path for kubernetes pods logs?

10/22/2017

What is the absolute path for kubernetes pods logs?
When I tried kubectl logs pod, I can see logs of pod. I want to know the log file path of running pod.

kubectl logs npapp-0r9jw

output: rectory /hab/pkgs/core/tomcat8/8.5.9/20170514144202/tc/webapps/ROOT has finished in 21 ms
national-parks.default(O): 22-Oct-2017 05:33:54.526 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /hab/pkgs/core/tomcat8/8.5.9/20170514144202/tc/webapps/manager
national-parks.default(O): 22-Oct-2017 05:33:54.564 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /hab/pkgs/core/tomcat8/8.5.9/20170514144202/tc/webapps/manager has finished in 38 ms
national-parks.default(O): 22-Oct-2017 05:33:54.564 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /hab/pkgs/core/tomcat8/8.5.9/20170514144202/tc/webapps/host-manager
national-parks.default(O): 22-Oct-2017 05:33:54.595 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /hab/pkgs/core/tomcat8/8.5.9/20170514144202/tc/webapps/host-manager has finished in 31 ms
national-parks.default(O): 22-Oct-2017 05:33:54.599 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-8080]
national-parks.default(O): 22-Oct-2017 05:33:54.613 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [ajp-nio-8009]
national-parks.default(O): 22-Oct-2017 05:33:54.620 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 2735 ms

Where can I see absolute log file path?

-- krishna bh
containers
kubernetes
logging
logstash

2 Answers

10/22/2017

If you look into Kubernetes sources, you will see pkg/routes/logs.go, which will serve the content of files within (by default) /var/log (serving static files following this example)

func logFileHandler(req *restful.Request, resp *restful.Response) {
    logdir := "/var/log"
    actual := path.Join(logdir, req.PathParameter("logpath"))
    http.ServeFile(resp.ResponseWriter, req.Request, actual)
}

As you can see in kubernetes/kubernetes issue 53022:

The current symlink /var/log/containers is pointing to /var/log/pods/pod_UID/*.logs

So the full absolute path for logs is:

/var/log/pods/pod_UID/*.logs

Update 2019:

This issue also refers to analytics-platform-helm-charts PR 91:

Symlink /var/log/containers has been deprecated in favor of /var/log/pods for our version of the docker daemon for kubernetes metadata.

See this Kubernetes CRI (Nov. 2018)

Kubelet will be configured with a root directory (e.g., /var/log/pods or /var/lib/kubelet/logs/) to store all container logs. Below is an example of a path to the log of a container in a pod.

/var/log/pods/<podUID>/<containerName>_<instance#>.log

In CRI, this is implemented by setting the pod-level log directory when creating the pod sandbox, and passing the relative container log path when creating a container.

PodSandboxConfig.LogDirectory: /var/log/pods/<podUID>/
ContainerConfig.LogPath: <containerName>_<instance#>.log
-- VonC
Source: StackOverflow

11/18/2019

The answer by VonC is not 100% accurate - it should be /var/log/pods/<namespace>_<pod_name>_<pod_id>/<container_name>/*.log


Also, the location of the actual log files depends on the container runtime you're using. Docker stores its container logs at /var/lib/docker/containers.

When working with Kubernetes, you can access container logs using the absolute log path /var/log/pods/<namespace>_<pod_name>_<pod_id>/<container_name>/*.log. These .log files symlinks to the actual log files stored by the container runtime.

-- d4nyll
Source: StackOverflow