kubectl attach [page]deterministic
Attach to a running container
##
Attach to a process that is already running inside an existing container.
``` kubectl attach (POD | TYPE/NAME) -c CONTAINER ```
##
``` # Get output from running pod mypod; use the 'kubectl.kubernetes.io/default-container' annotation # for selecting the container to be attached or the first container in the pod will be chosen kubectl attach mypod # Get output from ruby-container from pod mypod kubectl attach mypod -c ruby-container # Switch to raw terminal mode; sends stdin to 'bash' in ruby-container from pod mypod # and sends stdout/stderr from 'bash' back to the client kubectl attach mypod -c ruby-container -i -t # Get output from the first pod of a replica set named nginx kubectl attach rs/nginx ```
##
<table style="width: 100%; table-layout: fixed;"> <colgroup> <col span="1" style="width: 10px;" /> <col span="1" /> </colgroup> <tbody>
<tr> <td colspan="2">-c, --container string</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Container name. If omitted, use the kubectl.kubernetes.io/default-container annotation for selecting the container to be attached or the first container in the pod will be chosen</p></td> </tr>
<tr> <td colspan="2">--detach-keys string Default: "ctrl-p,ctrl-q"</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Override the key sequence for detaching a container</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 attach</p></td> </tr>
<tr> <td colspan="2">--pod-running-timeout duration Default: 1m0s</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>The length of time (like 5s, 2m, or 3h, higher than zero) to wait until at least one pod is running</p></td> </tr>
<tr> <td colspan="2">-q, --quiet</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Only print output from the remote session</p></td> </tr>
<tr> <td colspan="2">-i, --stdin</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Pass stdin to the container</p></td> </tr>
<tr> <td colspan="2">-t, --tty</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Stdin is a TTY</p></td> </tr>
</tbody> </table>
##
<table style="width: 100%; table-layout: fixed;"> <colgroup> <col span="1" style="width: 10px;" /> <col span="1" /> </colgroup> <tbody>
<tr> <td colspan="2">--as string</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Username to impersonate for the operation. User could be a regular user or a service account in a namespace.</p></td> </tr>
<tr> <td colspan="2">--as-group strings</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Group to impersonate for the operation, this flag can be repeated to specify multiple groups.</p></td> </tr>
<tr> <td colspan="2">--as-uid string</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>UID to impersonate for the operation.</p></td> </tr>
<tr> <td colspan="2">--as-user-extra strings</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>User extras to impersonate for the operation, this flag can be repeated to specify multiple values for the same key.</p></td> </tr>
<tr> <td colspan="2">--cache-dir string Default: "$HOME/.kube/cache"</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Default cache directory</p></td> </tr>
<tr> <td colspan="2">--certificate-authority string</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Path to a cert file for the certificate authority</p></td> </tr>
<tr> <td colspan="2">--client-certificate string</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;" …(trimmed)