kubectl logs
Synopsis
Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional.
kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]
Examples
# Return snapshot logs from pod nginx with only one container
kubectl logs nginx
# Return snapshot logs from pod nginx with multi containers
kubectl logs nginx --all-containers=true
# Return snapshot logs from all containers in pods defined by label app=nginx
kubectl logs -l app=nginx --all-containers=true
# Return snapshot of previous terminated ruby container logs from pod web-1
kubectl logs -p -c ruby web-1
# 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 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
Options
--all-containers | |
Get all containers' logs in the pod(s). | |
-c, --container string | |
Print the logs of this container | |
-f, --follow | |
Specify if the logs should be streamed. | |
-h, --help | |
help for logs | |
--ignore-errors | |
If watching / following pod logs, allow for any errors that occur to be non-fatal | |
--insecure-skip-tls-verify-backend | |
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. | |
--limit-bytes int | |
Maximum bytes of logs to return. Defaults to no limit. | |
--max-log-requests int Default: 5 | |
Specify maximum number of concurrent logs to follow when using by a selector. Defaults to 5. | |
--pod-running-timeout duration Default: 20s | |
The length of time (like 5s, 2m, or 3h, higher than zero) to wait until at least one pod is running | |
--prefix | |
Prefix each log line with the log source (pod name and container name) | |
-p, --previous | |
If true, print the logs for the previous instance of the container in a pod if it exists. | |
-l, --selector string | |
Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2). Matching objects must satisfy all of the specified label constraints. | |
--since duration | |
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. | |
--since-time string | |
Only return logs after a specific date (RFC3339). Defaults to all logs. Only one of since-time / since may be used. | |
--tail int Default: -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. | |
--timestamps | |
Include timestamps on each line in the log output |
--as string | |
Username to impersonate for the operation. User could be a regular user or a service account in a namespace. | |
--as-group strings | |
Group to impersonate for the operation, this flag can be repeated to specify multiple groups. | |
--as-uid string | |
UID to impersonate for the operation. | |
--azure-container-registry-config string | |
Path to the file containing Azure container registry configuration information. | |
--cache-dir string Default: "$HOME/.kube/cache" | |
Default cache directory | |
--certificate-authority string | |
Path to a cert file for the certificate authority | |
--client-certificate string | |
Path to a client certificate file for TLS | |
--client-key string | |
Path to a client key file for TLS | |
--cloud-provider-gce-l7lb-src-cidrs cidrs Default: 130.211.0.0/22,35.191.0.0/16 | |
CIDRs opened in GCE firewall for L7 LB traffic proxy & health checks | |
--cloud-provider-gce-lb-src-cidrs cidrs Default: 130.211.0.0/22,209.85.152.0/22,209.85.204.0/22,35.191.0.0/16 | |
CIDRs opened in GCE firewall for L4 LB traffic proxy & health checks | |
--cluster string | |
The name of the kubeconfig cluster to use | |
--context string | |
The name of the kubeconfig context to use | |
--default-not-ready-toleration-seconds int Default: 300 | |
Indicates the tolerationSeconds of the toleration for notReady:NoExecute that is added by default to every pod that does not already have such a toleration. | |
--default-unreachable-toleration-seconds int Default: 300 | |
Indicates the tolerationSeconds of the toleration for unreachable:NoExecute that is added by default to every pod that does not already have such a toleration. | |
--disable-compression | |
If true, opt-out of response compression for all requests to the server | |
--insecure-skip-tls-verify | |
If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure | |
--kubeconfig string | |
Path to the kubeconfig file to use for CLI requests. | |
--match-server-version | |
Require server version to match client version | |
-n, --namespace string | |
If present, the namespace scope for this CLI request | |
--password string | |
Password for basic authentication to the API server | |
--profile string Default: "none" | |
Name of profile to capture. One of (none|cpu|heap|goroutine|threadcreate|block|mutex) | |
--profile-output string Default: "profile.pprof" | |
Name of the file to write the profile to | |
--request-timeout string Default: "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. | |
-s, --server string | |
The address and port of the Kubernetes API server | |
--storage-driver-buffer-duration duration Default: 1m0s | |
Writes in the storage driver will be buffered for this duration, and committed to the non memory backends as a single transaction | |
--storage-driver-db string Default: "cadvisor" | |
database name | |
--storage-driver-host string Default: "localhost:8086" | |
database host:port | |
--storage-driver-password string Default: "root" | |
database password | |
--storage-driver-secure | |
use secure connection with database | |
--storage-driver-table string Default: "stats" | |
table name | |
--storage-driver-user string Default: "root" | |
database username | |
--tls-server-name string | |
Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used | |
--token string | |
Bearer token for authentication to the API server | |
--user string | |
The name of the kubeconfig user to use | |
--username string | |
Username for basic authentication to the API server | |
--version version[=true] | |
--version, --version=raw prints version information and quits; --version=vX.Y.Z... sets the reported version | |
--warnings-as-errors | |
Treat warnings received from the server as errors and exit with a non-zero exit code |
See Also
- kubectl - kubectl controls the Kubernetes cluster manager
This page is automatically generated.
If you plan to report an issue with this page, mention that the page is auto-generated in your issue description. The fix may need to happen elsewhere in the Kubernetes project.