KUBERNETES(1)(kubernetes)

✨ NAME ✨

kubectl logs β€” bestie, this prints the logs for a container in a pod πŸ’–

This one lives in the kubernetes manual, section 1. Yeah. You're in the right place. 🫢


πŸŽ€ SYNOPSIS πŸŽ€

kubectl logs [OPTIONS]

πŸ’… DESCRIPTION πŸ’…

Okay so real talk: this prints the logs for a container in a pod, or for a specified resource. That's it, that's the whole vibe. 🌸

And here's the little gift: if the pod has only one container, the container name is optional. One container = no need to name names. Slay. ✨


πŸ‘‘ OPTIONS πŸ‘‘

  • --all-containers=false β€” grab the logs from every container in the pod(s). All of them. No container left behind. πŸ’–
  • --all-pods=false β€” get logs from all pod(s). Heads up: this sets prefix to true. So it just does that for you, periodt. πŸ”₯
  • -c, --container="" β€” print the logs of this specific container. Pick your fave. πŸŽ€
  • -f, --follow=false β€” specify if the logs should be streamed. Like, live. It keeps going. Obsessed. 🌊
  • --ignore-errors=false β€” if you're watching / following pod logs, this lets any errors that happen be non-fatal. The drama does not stop the stream. πŸ’…
  • --insecure-skip-tls-verify-backend=false β€” skip 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. Use with care, bestie, no cap. 😭
  • --limit-bytes=0 β€” maximum bytes of logs to return. Defaults to no limit. All you can eat. πŸ“
  • --max-log-requests=5 β€” specify the maximum number of concurrent logs to follow when using by a selector. Defaults to 5. Five at once, iconic. ✨
  • --pod-running-timeout=20s β€” the length of time (like 5s, 2m, or 3h, higher than zero) to wait until at least one pod is running. Manifesting a running pod for you. πŸ™ˆ
  • --prefix=false β€” prefix each log line with the log source (pod name and container name). So you always know who said what. πŸ’œ
  • -p, --previous=false β€” if true, print the logs for the previous instance of the container in a pod, if it exists. The ex. The one before. πŸ‘»
  • -l, --selector="" β€” selector (label query) to filter on, supports '=', '==', '!=', 'in', 'notin'. (e.g. -l key1=value1,key2=value2,key3 in (value3)). Matching objects must satisfy all of the specified label constraints. All of them. Not just the cute ones. 🌈
  • --since=0s β€” only 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. Pick a lane bestie. ⭐
  • --since-time="" β€” only return logs after a specific date (RFC3339). Defaults to all logs. Only one of since-time / since may be used. Same rule, other twin. πŸ¦‹
  • --tail=-1 β€” lines of recent log file to display. Defaults to -1 with no selector, showing all log lines, otherwise 10, if a selector is provided. Yes the default literally changes based on the selector, it's giving main character energy. πŸ’…
  • --timestamps=false β€” include timestamps on each line in the log output. Time-stamped and gorgeous. ⏰

🌈 OPTIONS INHERITED FROM PARENT COMMANDS 🌈

  • --as="" β€” username to impersonate for the operation. User could be a regular user or a service account in a namespace. Be someone else, legally. ✨
  • --as-group=[] β€” group to impersonate for the operation, this flag can be repeated to specify multiple groups. Stack 'em. πŸŽ€
  • --as-uid="" β€” UID to impersonate for the operation.
  • --as-user-extra=[] β€” user extras to impersonate for the operation, this flag can be repeated to specify multiple values for the same key.
  • --cache-dir="/home/username/.kube/cache" β€” default cache directory. Cozy little home for your cache. 🏠
  • --certificate-authority="" β€” path to a cert file for the certificate authority.
  • --client-certificate="" β€” path to a client certificate file for TLS.
  • --client-key="" β€” path to a client key file for TLS.
  • --cluster="" β€” the name of the kubeconfig cluster to use.
  • --context="" β€” the name of the kubeconfig context to use.
  • --disable-compression=false β€” if true, opt-out of response compression for all requests to the server. Raw and uncompressed. 🫢
  • --insecure-skip-tls-verify=false β€” if true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure. Saying it louder for the people in the back. 😭
  • --kubeconfig="" β€” path to the kubeconfig file to use for CLI requests.
  • --kuberc="" β€” path to the kuberc file to use for preferences. This can be disabled by exporting KUBECTL_KUBERC=false feature gate or turning off the feature KUBERC=off.
  • --match-server-version=false β€” require server version to match client version. They must match. It's giving soulmates. πŸ’–
  • -n, --namespace="" β€” if present, the namespace scope for this CLI request.
  • --password="" β€” password for basic authentication to the API server.
  • --profile="none" β€” name of profile to capture. One of (none|cpu|heap|goroutine|threadcreate|block|mutex|trace).
  • --profile-output="profile.pprof" β€” name of the file to write the profile to.
  • --proxy-url="" β€” proxy URL to use for requests to the API server.
  • --request-timeout="0" β€” the length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. Zero = we wait forever, apparently. πŸ’€
  • -s, --server="" β€” the address and port of the Kubernetes API server.
  • --tls-server-name="" β€” server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used.
  • --token="" β€” bearer token for authentication to the API server.
  • --user="" β€” the name of the kubeconfig user to use.
  • --username="" β€” username for basic authentication to the API server.
  • --version=false β€” --version, --version=raw prints version information and quits; --version=vX.Y.Z... sets the reported version. Tell me who you are and then leave. πŸ‘‘
  • --warnings-as-errors=false β€” treat warnings received from the server as errors and exit with a non-zero exit code. Warnings get promoted. Congrats to them. πŸ”₯

πŸ¦‹ EXAMPLE πŸ¦‹

Okay bestie, here's the whole mood board of things you can actually type:

# Return snapshot logs from pod nginx with only one container
kubectl logs nginx

# Return snapshot logs from pod nginx, prefixing each line with the source pod and container name
kubectl logs nginx --prefix

# Return snapshot logs from pod nginx, limiting output to 500 bytes
kubectl logs nginx --limit-bytes=500

# Return snapshot logs from pod nginx, waiting up to 20 seconds for it to start running.
kubectl logs nginx --pod-running-timeout=20s

# Return snapshot logs from pod nginx with multi containers
kubectl logs nginx --all-containers=true

# Return snapshot logs from all pods in the deployment nginx
kubectl logs deployment/nginx --all-pods=true

# Return snapshot logs from all containers in pods defined by label app=nginx
kubectl logs -l app=nginx --all-containers=true

# Return snapshot logs from all pods defined by label app=nginx, limiting concurrent log requests to 10 pods
kubectl logs -l app=nginx --max-log-requests=10

# Return snapshot of previous terminated ruby container logs from pod web-1
kubectl logs -p -c ruby web-1

# Begin streaming the logs from pod nginx, continuing even if errors occur
kubectl logs nginx -f --ignore-errors=true

# Begin streaming the logs of the ruby container in pod web-1
kubectl logs -f -c ruby web-1

# Begin streaming the logs from all containers in pods defined by label app=nginx
kubectl logs -f -l app=nginx --all-containers=true

# Display only the most recent 20 lines of output in pod nginx
kubectl logs --tail=20 nginx

# Show all logs from pod nginx written in the last hour
kubectl logs --since=1h nginx

# Show all logs with timestamps from pod nginx starting from August 30, 2024, at 06:00:00 UTC
kubectl logs nginx --since-time=2024-08-30T06:00:00Z --timestamps=true

# Show logs from a kubelet with an expired serving certificate
kubectl logs --insecure-skip-tls-verify-backend nginx

# Return snapshot logs from first container of a job named hello
kubectl logs job/hello

# Return snapshot logs from container nginx-1 of a deployment named nginx
kubectl logs deployment/nginx -c nginx-1

πŸ’œ SEE ALSO πŸ’œ


πŸ“œ HISTORY πŸ“œ

January 2015, originally compiled by Eric Paris (eparis at redhat dot com) based on the kubernetes source material β€” but hopefully they have been automatically generated since! πŸŽ€


πŸ’– And that's a wrap! This page came out of the Manuals manual, User edition, filed under KUBERNETES(1)(kubernetes), and it's been a January 2015 era baddie this whole time. Bye bestie, go read some logs! πŸ¦‹βœ¨
πŸ“¦ where this page comes from