I would like to run a one-off container Pod from the command line in my Kubernetes cluster. I am looking for the equivalent of:
docker run --rm -it centos /b
It looks like the simplest way is:
kubectl run tmp-shell --rm -i --tty --image centos -- /bin/bash
Notes:
Deployment
named tmp-shell
. This happens any time you use kubectl run
.--rm
ensures this Deployment
and all of its components are deleted when you exit the shell. If you omitted --rm
, you can delete it manually with kubectl delete deploy/tmp-shell
. --rm
. You will then be able to reattach with: kubectl attach $pod-name -c $pod-container -i -t
after you exit the shell.If your shell does not start, check whether your cluster is out of resources (kubectl describe nodes
). You can control the resources this deployment is requesting with --requests
:
--requests='': The resource requirement requests for this container. For example, 'cpu=100m,memory=256Mi'. Note that server side components may assign requests depending on the server configuration, such as limit ranges.
(Inspired by https://gc-taylor.com/blog/2016/10/31/fire-up-an-interactive-bash-pod-within-a-kubernetes-cluster)