Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

kubernetes

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.

like image 510
Ankur Avatar asked Apr 10 '17 06:04

Ankur


3 Answers

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.

like image 67
jaxxstorm Avatar answered Sep 22 '22 12:09

jaxxstorm


  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.

like image 38
d4nyll Avatar answered Sep 21 '22 12:09

d4nyll


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

like image 45
iomv Avatar answered Sep 24 '22 12:09

iomv