logs

Return snapshot logs from pod nginx with only one container

  1. kubectl logs nginx

Return snapshot logs from pod nginx with multi containers

  1. kubectl logs nginx --all-containers=true

Return snapshot logs from all containers in pods defined by label app=nginx

  1. kubectl logs -l app=nginx --all-containers=true

Return snapshot of previous terminated ruby container logs from pod web-1

  1. kubectl logs -p -c ruby web-1

Begin streaming the logs of the ruby container in pod web-1

  1. kubectl logs -f -c ruby web-1

Begin streaming the logs from all containers in pods defined by label app=nginx

  1. kubectl logs -f -l app=nginx --all-containers=true

Display only the most recent 20 lines of output in pod nginx

  1. kubectl logs --tail=20 nginx

Show all logs from pod nginx written in the last hour

  1. kubectl logs --since=1h nginx

Show logs from a kubelet with an expired serving certificate

  1. kubectl logs --insecure-skip-tls-verify-backend nginx

Return snapshot logs from first container of a job named hello

  1. kubectl logs job/hello

Return snapshot logs from container nginx-1 of a deployment named nginx

  1. kubectl logs deployment/nginx -c nginx-1

Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional.

Usage

$ kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]

Flags

NameShorthandDefaultUsage
all-containersfalseGet all containers’ logs in the pod(s).
containercPrint the logs of this container
followffalseSpecify if the logs should be streamed.
ignore-errorsfalseIf watching / following pod logs, allow for any errors that occur to be non-fatal
insecure-skip-tls-verify-backendfalseSkip verifying the identity of the kubelet that logs are requested from. In theory, an attacker could provide invalid log content back. You might want to use this if your kubelet serving certificates have expired.
limit-bytes0Maximum bytes of logs to return. Defaults to no limit.
max-log-requests5Specify maximum number of concurrent logs to follow when using by a selector. Defaults to 5.
pod-running-timeout20sThe length of time (like 5s, 2m, or 3h, higher than zero) to wait until at least one pod is running
prefixfalsePrefix each log line with the log source (pod name and container name)
previouspfalseIf true, print the logs for the previous instance of the container in a pod if it exists.
selectorlSelector (label query) to filter on.
since0sOnly return logs newer than a relative duration like 5s, 2m, or 3h. Defaults to all logs. Only one of since-time / since may be used.
since-timeOnly return logs after a specific date (RFC3339). Defaults to all logs. Only one of since-time / since may be used.
tail-1Lines of recent log file to display. Defaults to -1 with no selector, showing all log lines otherwise 10, if a selector is provided.
timestampsfalseInclude timestamps on each line in the log output