convert docker run command to kubectl for one time execution

9/8/2020

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?

-- Deano
docker
kubernetes
minio

1 Answer

9/8/2020

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:

  1. Run the container in a Pod:
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 container

NOTE the image's entrypoint is overridden by --command and /bin/sh

  1. Exec into the container, e.g.:
kubectl exec --stdin --tty minio -- mc --help
-- DazWilkin
Source: StackOverflow