Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see logs of terminated pods

I am running selenium hubs and my pods are getting terminated frequently. I would like to look at the logs of the pods which are terminated. How to do it?

NAME                                               READY     STATUS              RESTARTS   AGE chrome-75-0-0e5d3b3d-3580-49d1-bc25-3296fdb52666   0/2       Terminating         0          49s chrome-75-0-29bea6df-1b1a-458c-ad10-701fe44bb478   0/2       Terminating         0          23s chrome-75-0-8929d8c8-1f7b-4eba-96f2-918f7a0d77f5   0/2       ContainerCreating   0          7s  kubectl logs chrome-75-0-8929d8c8-1f7b-4eba-96f2-918f7a0d77f5 Error from server (NotFound): pods "chrome-75-0-8929d8c8-1f7b-4eba-96f2-918f7a0d77f5" not found $ kubectl logs chrome-75-0-8929d8c8-1f7b-4eba-96f2-918f7a0d77f5 --previous Error from server (NotFound): pods "chrome-75-0-8929d8c8-1f7b-4eba-96f2-918f7a0d77f5" not found 
like image 314
SunilS Avatar asked Jul 12 '19 12:07

SunilS


People also ask

How do I view pods logs?

Checking the logs of a running pod All that you need to do to do that is to run the following command: kubectl logs nginx-7d8b49557c-c2lx9.

How do I list a terminated pod in Kubernetes?

if the update deployment "say a new image". pod will be terminated and new pod will be created. you can get the pod details from depoyment yaml. if you want to get details of previous pod you have see "spec" section of previous deployment yaml.

How do I check old pod logs in Kubernetes?

You can see the logs of a particular container by running the command kubectl logs <container name> . Here's an example for Nginx logs generated in a container. If you want to access logs of a crashed instance, you can use –previous . This method works for clusters with a small number of containers and instances.

How do I get all the logs from Kubernetes pod?

If you want to show logs of all pods, you can use -l and specify a lable, but at the same time -f won't be used. "but this will choose one pod of the deployment, not all pods" -> true and I've spent a lot of time debugging my app before realizing that not all logs were being displayed.


1 Answers

Running kubectl logs -p will fetch logs from existing resources at API level. This means that terminated pods' logs will be unavailable using this command.

As mentioned in other answers, the best way is to have your logs centralized via logging agents or directly pushing these logs into an external service.

Alternatively and given the logging architecture in Kubernetes, you might be able to fetch the logs directly from the log-rotate files in the node hosting the pods. However, this option might depend on the Kubernetes implementation as log files might be deleted when the pod eviction is triggered.

like image 196
yyyyahir Avatar answered Sep 27 '22 00:09

yyyyahir