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 setsprefixtotrue. 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 to5. Five at once, iconic. β¨--pod-running-timeout=20sβ the length of time (like5s,2m, or3h, 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β iftrue, 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 like5s,2m, or3h. Defaults to all logs. Only one ofsince-time/sincemay be used. Pick a lane bestie. β--since-time=""β only return logs after a specific date (RFC3339). Defaults to all logs. Only one ofsince-time/sincemay be used. Same rule, other twin. π¦--tail=-1β lines of recent log file to display. Defaults to-1with no selector, showing all log lines, otherwise10, 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β iftrue, opt-out of response compression for all requests to the server. Raw and uncompressed. π«Ά--insecure-skip-tls-verify=falseβ iftrue, 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 exportingKUBECTL_KUBERC=falsefeature gate or turning off the featureKUBERC=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=rawprints 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
- arch rolling: kubectl 1.37.2-1 Β· Apache-2.0
- fedora 43: kubernetes1.37-client 1.37.0-3.fc43
- fedora 43: kubernetes1.37-client 1.37.1-1.fc43 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-3-Clause-HP AND CC-BY-4.0 AND ISC AND MIT AND MPL-2.0
- fedora 44: kubernetes1.37-client 1.37.0-3.fc44
- fedora 44: kubernetes1.37-client 1.37.1-1.fc44 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-3-Clause-HP AND CC-BY-4.0 AND ISC AND MIT AND MPL-2.0
- nixpkgs unstable: kubectl 1.37.2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms