I'm trying to run a docker image once to execute a task using a popular S3 client minio the environment I'm dealing with use Kubernetes.
I can get shell access to execute tasks like so:
docker run -it minio/mc --restart=Never --rm /bin/sh
similarly, I'm able to run busybox image in my K8S cluster.
kubectl run busybox -i --tty --image=busybox --restart=Never --rm -- sh
However, I'm unable to get that mc client to work the same way it does with the previous example.
kubectl run minio -i --tty --image=minio/mc --restart=Never --rm -- /bin/sh
My shell would just exit, any ideas on how to keep the shell open? or how to pass bash commands to it before it dies?
This issue arises when container(s) in a Pod run some process(es) that complete. When its containers exit, the Pod completes. It is more common to have container(s) in a Pod that run continuously.
A solution to this completing problem is thus to keep the container running:
kubectl run minio \
--image=minio/mc \
--restart=Never \
--command \
-- /bin/sh -c 'while true; do sleep 5s; done'
NOTE the Pod is kept running by the
while
loop in the containerNOTE the image's entrypoint is overridden by
--command
and/bin/sh
kubectl exec --stdin --tty minio -- mc --help