kubectl attach - Attach to a running container
kubectl attach (POD | TYPE/NAME) [-c CONTAINER] [-i] [-t] [--pod-running-timeout=1m0s]
Options you will use
-c, --container=NAME- which container
-i, --stdin- pass stdin to the container (it must have been started with stdin: true)
-t, --tty- stdin is a TTY (the container must have tty: true)
-q, --quiet- only print output from the remote session
--pod-running-timeout=1m0s- how long to wait for the pod to be running
Examples
$ kubectl attach web-5d8cthe main process's stdout/stderr from now on (Ctrl+C detaches)
$ kubectl attach shell -c shell -i -tback into a kubectl run -it shell after you detached
Gotchas
- attach is not exec: it connects to the process that is already PID 1 of the container, it does not start a new one. Exiting that shell ends the container.
- Unlike logs, attach shows only what is written after you attach.
Try kubectl attach in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.