Kubernetes Pods failed hours ago, how to debug a terminated pod

7/13/2021

I have a deployment of pods which failed 22h ago, how often does Kubernetes log-rotate its logs?

Is there any possibility to view the logs of the deployment but 22 hours ago?

Thanks

-- LearningPath
kubernetes
logging

3 Answers

7/13/2021

You can use kubectl logs --previous to retrieve logs from a previous instantiation of a container.

-- rassakra
Source: StackOverflow

7/13/2021
  1. Kubernetes does NOT provide built-in log rotation.

  2. Check official Debug Running Pods documentation:

If your container has previously crashed, you can access the previous container's crash log with:

kubectl logs --previous ${POD_NAME} ${CONTAINER_NAME}
  1. In my opinion you are asking not about logs on pod, you are more interested in full debug. Your starting point is again official documentation Troubleshoot Applications-Debugging Pods. ANd start check with kubectl describe pods ${POD_NAME}

4.All I wrote above is great, however sometimes the only way to get the logs is @confused genius answer.

-- Vit
Source: StackOverflow

7/13/2021

I think we can not retrieve logs from a pod that is not in ready state. We can get the logs of the container inside the pod , By logging into the worker node where pod was running .

  • docker ps -a | grep <pod name>
  • docker logs <container name/id from above output
-- confused genius
Source: StackOverflow