In those cases where you need a throw-away interactive shell within your cluster:
$ kubectl run test-shell --rm -i --tty --image ubuntu -- bash
You may, of course, use a different image or shell. Some of the arguments explained:
test-shell: This ends up being the name of the Deployment that is created. Your pod name will typically be this plus a unique hash or ID at the end.
--rm: Delete any resources we've created once we detach. When you exit out of your session, this cleans up the Deployment and Pod.
-i/--tty: The combination of these two are what allows us to attach to an interactive session.
--: Delimits the end of the kubectl run options from the positional arg (bash).
bash: Overrides the container's CMD. In this case, we want to launch bash as our container's command.
Notes:
- If you don't see a command prompt, try pressing enter.
- You'll need to update your apt cache before you can install packages:
$ apt update
$ apt install telnet
Once you are done with your troubleshooting:
$ exit
Post-exit, the Deployment and Pod that kubectl created will both be stopped and deleted, taking with it our container and anything we did within it.
Top comments (0)