When a container which runs as part of a Kubernetes pod crashes, does running kubectl logs <pod-name>
will give me the logs of the crashed container?
From an experiment I did – it doesn’t, but I wonder if that’s something that is well defined as part of kubernetes way of operation or just something arbitrary in my specific case?
3
No, you will not be able to get a crashed containers logs after the pod has exited and left. You need to handle the logging yourself. You could mount a network file share (such as EFS on AWS) on to the pod and have the logs written directly into it, which would mean the logs are persisted on the file share. Or you could use the ELK stack to push logs to elasticsearch. Or you could have your application directly write its logs into a persistent volume hosted somewhere. But ultimately this is not something Kubernetes provides.