How to check failed container logs in Kubernetes

4/2/2021

Before i check the logs, pods are failing and removed by jenkins and I am unable to see the logs. How can i check the logs of the pods that are removed.

is there any simple way to save the logs in kubernetes.

I don't have any logging system for my kubernetes.

In a fraction of seconds, it keeps creating and deleting because of some error. I want to find what the error is. before i check the logs, the container name is changed.

Thanks,

-- Vijay
jenkins
kubernetes

1 Answer

4/2/2021

Most probably you meant "pods are failing and removed by kubernetes and I am unable to see the logs." This is kubernetes itself who manage API objects, not jenkins.

Answering your question directly - you are not able to fetch any logs from any of your containers once related POD was deleted. Deletion pod means wiping all pod's containers with all the data included. Logs were deleted in the moment your pod was terminated.

By default, if a container restarts, the kubelet keeps one terminated container with its logs. If a pod is evicted from the node, all corresponding containers are also evicted, along with their logs.

If you pod were alive - you would be able to use ----previous flag to check the logs, but unfortunatelly thats not your case.

There are a lot of similar questions - and the only main suggestion is to set up some log aggregation system that will store logs separately. IN that case you wont lose them and will be able at least check them.

-- Vit
Source: StackOverflow