kubectl-attach
attaches to a running container in a pod
TLDR
SYNOPSIS
kubectl attach (POD | TYPE/NAME) [-c CONTAINER] [options]
DESCRIPTION
kubectl attach connects your terminal to the stdin/stdout/stderr streams of a process already running inside a container. Unlike kubectl exec, which spawns a new process in the container, attach hooks into the container's PID 1 (the main command defined in the image or pod spec), so you see the same output as the container's log stream and can send input to that process when it was started with stdin open.Use -i -t together to get a full interactive shell experience when the container was started with an interactive command (e.g., a pod created with `kubectl run -it`). To attach to a specific container in a multi-container pod, pass -c. Detach with the escape sequence Ctrl-P Ctrl-Q to leave the process running.
PARAMETERS
-c, --container name
Container name. If omitted, uses the `kubectl.kubernetes.io/default-container` annotation or the first container in the pod.-i, --stdin
Pass stdin to the container.-t, --tty
Stdin is a TTY (allocate a terminal).-q, --quiet
Only print output from the remote session.--pod-running-timeout duration
Time to wait until at least one pod is running (default: 1m0s).-n, --namespace name
Namespace scope for the request.--context name
Kubeconfig context to use.--kubeconfig path
Path to the kubeconfig file.
CAVEATS
The target container must have been started with stdin open (stdin: true in the pod spec or -i on `kubectl run`) for input to be delivered. Attaching does not restart the process; closing the connection improperly with Ctrl-C may signal the process. Only one attach session per container stream is reliable.
SEE ALSO
kubectl(1), kubectl-exec(1), kubectl-logs(1), kubectl-run(1)
