How to view the storage path of k8s logs?
There are several ways to view the storage path of logs in Kubernetes.
- Use the kubectl command to view the logs of a Pod.
- Show the logs for the specified pod.
- Viewing logs of a specific container using the kubectl command:
- Retrieve the logs of a specific container within a pod using the command “kubectl logs
-c “. - Use the kubectl command to view the logs and output them in real-time.
- Show the continuous logs of a specific pod using kubectl.
- Retrieve the log path of a Pod using the kubectl command:
- Provide a detailed description of the pod with the specified name using kubectl.
- Look for the “Mounts” field in the output, which lists the mounting paths of the containers. You can find log files in the corresponding mounting paths.
- Login to the node host, and search for the log files of the container:
Begin by using the kubectl command to obtain the IP address of the node host where the Pod is located. - Display the details of the specified pod and filter the output to only show the Node information.
- Next, log in to the corresponding node host and locate the path to the container’s log files. By default, the logs for pods are stored in the /var/log/containers directory, named in the format of “
.log”.
In addition to the methods mentioned above, visual tools such as Kibana and ELK can also be used to view and analyze logs in a Kubernetes cluster.