Running a second process in a container

I frequently find it more useful to run an additional command in a Pod rather than attempting to attach to the Pod. You can do this with the kubectl exec command.

As of Kubernetes 1.8, kubectl exec doesn't support the deployment/name shortcut that we have used for the logs or attach commands, so you will need to specify the specific Pod name you want to interact with. If you just want to open an interactive shell in the Pod, you could run the following command:

kubectl get podsNAME                   READY STATUS  RESTARTS AGEflask-1908233635-d6stj 1/1   Running 0        1m

Using the name of the running pod, invoke kubectl exec to open an interactive shell within it:

kubectl exec flask-1908233635-d6stj -it -- /bin/sh# ps auxPID ...

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.