Skip to main content

Using kubectl logs

Logs for your application can be seen by using kubectl logs. A few examples of using this command are shown below. See the Kubernetes documentation for complete details.

CommandResult
kubectl logs MY_POD# dump pod logs (stdout)
kubectl logs -l name=myLabel# dump pod logs, with label name=myLabel (stdout)
kubectl logs MY_POD --previous# dump pod logs (stdout) for a previous instantiation of a container
kubectl logs MY_POD -c MY_CONTAINER# dump pod container logs (stdout, multi-container case)
kubectl logs -l name=myLabel -c MY_CONTAINER# dump pod logs, with label name=myLabel (stdout)
kubectl logs MY_POD -c MY_CONTAINER --previous# dump pod container logs (stdout, multi-container case) for a previous instantiation of a container
kubectl logs -f MY_POD# stream pod logs (stdout)
kubectl logs -f MY_POD -c MY_CONTAINER# stream all pods logs with label name=myLabel (stdout)# stream pod container logs (stdout, multi-container case)
kubectl logs -f -l name=myLabel --all-containers# stream all pods logs with label name=myLabel (stdout)

Note that if a pod is deleted, manually or due to scaling, rescheduling, or if its node fails, then earlier logs will be unavailable for that pod. So log streaming is a technique you should leverage.