Can I get hold of a log file in a kubernetes pod?

4/10/2017

Is there any way to get hold of the log file of the pod in Kubernetes cluster?

I know I can fetch logs using "kubectl exec log -f $POD_NAME" command but I want to get access to log file directly.

-- Ankur
kubernetes

3 Answers

11/18/2019
  1. Run kubectl get pod <pod_name> -n <namespace> -o jsonpath='{.spec.nodeName}' to get the node this Pod is running on.
  2. ssh into the node and you'll find the logs for the Pod at /var/log/pods/<namespace>_<pod_name>_<pod_id>/<container_name>/.

The files within the /var/log/pods/<namespace>_<pod_name>_<pod_id>/<container_name>/ directory are symlinks to where your container runtime writes its container log files. So unlike jaxxstorm's answer, it doesn't matter which container runtime you're running.

-- d4nyll
Source: StackOverflow

4/10/2017

It depends on the logging driver you're using I'm assuming you're using the default json logging driver here, but you can see the node the pod is scheduled on by using kubectl get po -o wide

Then, logon to that node and you'll see the docker logs of the container under /var/lib/docker/containers/<long_container_id>/<long_container_id>-json.log

You will need to use docker ps and docker inspect to determine the long container id.

-- jaxxstorm
Source: StackOverflow

3/14/2018

I normally retrieve it from /var/log/containers where you will find all the containers' logs deployed on that particular machine

-- iomv
Source: StackOverflow