Logs

Logs – System component logs record events happening in cluster, which can be very useful for debugging.

  1. Print the logs for a pod.

kubectl logs <pod_name>
  1. Print the logs for the last 6 hours for a pod.

kubectl logs --since=6h <pod_name>
  1. Get the most recent 50 lines of logs.

kubectl logs --tail=50 <pod_name>
  1. Get logs from a service and optionally select which container.

kubectl logs -f <service_name> [-c <$container>]
  1. Print the logs for a pod and follow new logs.

kubectl logs -f <pod_name>
  1. Print the logs for a container in a pod.

kubectl logs -c <container_name> <pod_name>
  1. Output the logs for a pod into a file named ‘pod.log’.

kubectl logs <pod_name> pod.log
  1. View the logs for a previously failed pod

kubectl logs --previous <pod_name>

Last updated