attach

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

  1. kubectl attach mypod

Get output from ruby-container from pod mypod

  1. 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

  1. kubectl attach mypod -c ruby-container -i -t

Get output from the first pod of a replica set named nginx

  1. kubectl attach rs/nginx

Attach to a process that is already running inside an existing container.

Usage

$ kubectl attach (POD | TYPE/NAME) -c CONTAINER

Flags

NameShorthandDefaultUsage
containercContainer 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
pod-running-timeout1m0sThe length of time (like 5s, 2m, or 3h, higher than zero) to wait until at least one pod is running
quietqfalseOnly print output from the remote session
stdinifalsePass stdin to the container
ttytfalseStdin is a TTY