Attaching to a running Pod

If your pod is up and running, and you want to run some commands from within the context of that container image, you can attach an interactive session to it. You do this via the kubectl attach command. A Pod must be active for this command to work, so if you’re trying to figure out why a Pod didn’t start properly, this command probably won’t help.

Attaching to a Pod will connect stdin into your process, and take anything from stdout and stderr and present it on the screen, so it’s more like an interactive version of the kubectl logs -f command. Whatever you specified for the container will need to take stdin in order for this to be useful. You will also need to explicitly enable the TTY in order to connect to it. ...

Get Kubernetes for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.