View log files of crashed pods in kubernetes

12/4/2015

Any idea to view the log files of a crashed pod in kubernetes? My pod is listing it's state as "CrashLoopBackOff" after started the replicationController. I search the available docs and couldn't find any.

-- Sudheera
kubernetes

3 Answers

12/4/2015

kubectl logs <podname> --previous

$ kubectl logs -h
-p, --previous[=false]: If true, print the logs for the previous instance of the container in a pod if it exists.

-- Prashanth B
Source: StackOverflow

12/4/2015

There was a bug in kubernetes that prevents logs obtaining for pods in CrashLoopBackOff state. Looks like it was fixed. Here issue on github with additional information

-- Vyacheslav Enis
Source: StackOverflow

3/10/2020

kubectl logs command only works if the pod is up and running. If they are not, you can use the kubectl events command.

kubectl get events -n <your_app_namespace> --sort-by='.metadata.creationTimestamp'

By default it does not sort the events, hence the --sort-by flag.

-- alltej
Source: StackOverflow