kubectl logs [page]deterministic
Print the logs for a container in a pod
##
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] ```
##
``` # 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 ```
##
<table style="width: 100%; table-layout: fixed;"> <colgroup> <col span="1" style="width: 10px;" /> <col span="1" /> </colgroup> <tbody>
<tr> <td colspan="2">--all-containers</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Get all containers' logs in the pod(s).</p></td> </tr>
<tr> <td colspan="2">--all-pods</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Get logs from all pod(s). Sets prefix to true.</p></td> </tr>
<tr> <td colspan="2">-c, --container string</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Print the logs of this container</p></td> </tr>
<tr> <td colspan="2">-f, --follow</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Specify if the logs should be streamed.</p></td> </tr>
<tr> <td colspan="2">-h, --help</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>help for logs</p></td> </tr>
<tr> <td colspan="2">--ignore-errors</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>If watching / following pod logs, allow for any errors that occur to be non-fatal</p></td> </tr>
<tr> <td colspan="2">--insecure-skip-tls-verify-backend</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>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.</p></td> </tr>
<tr> <td colspan="2">--limit-bytes …(trimmed)