How to check the historical logs of pods in k8s?

To view the historical logs of a Pod in Kubernetes, you can follow these steps:

  1. First, use the following command to list all running Pods:
kubectl get pods
  1. Choose the Pod to view the historical logs for and use the following command to list the Pod’s log files:
kubectl logs --previous <pod-name>

This will display the historical logs of the selected Pod. Please note that if the Pod has been deleted or restarted, its historical logs may not be viewable.

Furthermore, you can use the following command to obtain a summary of the logs for the Pod:

kubectl logs --previous --tail=<number-of-lines> <pod-name>

By replacing with the desired number of lines, you can retrieve the last few lines of logs for a specific Pod. By default, it will display the last 10 lines of logs.

Please note that the above command is only applicable to Pods with a single container. If the Pod has multiple containers, you need to specify the container name.

kubectl logs --previous <pod-name> -c <container-name>

Replace with the desired container name.

bannerAds