I am trying to use kubectl run command to pull an image from private registry and run a command from that. But I don't see an option to specify image pull secret. It looks like it is not possible to pass image secret as part for run command.
Is there any alternate option to pull a container and run a command using kubectl? The command output should be seen on the console. Also once the command finishes the pod should die.
You can use the overrides if you specify it right, it's an array in the end, that took me a bit to figure out, the below works on Kubernetes of at least 1.6:
--overrides='{ "apiVersion": "v1", "spec": { "imagePullSecrets": [{"name": "your-secret"}] } }'
for example
kubectl run -i -t hello-world --restart=Never --rm=true \
--image=eu.gcr.io/your-registry/hello-world \
--overrides='{ "apiVersion": "v1", "spec": { "imagePullSecrets": [{"name": "your-registry-secret"}] } }'
For Windows you'll need to escape the double quotes (and remove the two single quotes). You'll have something like
--overrides="{ \"apiVersion\": \"v1\", ...}] } }"
This response is conceptually right but it is not working anymore as the deployment API used by
kubectl run
has moved from v1. Have a look on the @Raman comment below to find the right way to do it.In my case, it worked with this override:
--overrides='{ "apiVersion": "apps/v1", "spec": { "template": { "spec": { "imagePullSecrets": [{"name": "your-registry-secret"}] } } } }'