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
In order to have a Pod
created instead of a Deployment
and to have it removed by itself when you exit it, try this:
kubectl run curl-debug --rm -i --tty --restart=Never --image=radial/busyboxplus:curl -- /bin/sh
The --restart=Never
flag is what it says to create a Pod
instead of a Deployment
object
Also - This image is lightweight, downloads fast and is good for network debugging.
Hope that helps
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)