Kubectl run busybox --image=busybox --restart=Never -- /bin/sh -c 'env'

Rahul:

kubectl run busybox --image=busybox --command --restart=Never -- env

OR
kubectl run busybox --image=busybox --restart=Never – /bin/sh -c ‘env’

I don’t see any difference in execution . what should we use in exam ? Are both fine or do we have scenarios?

Mayur Sharma:
{code}

kubectl run busybox --image=busybox --command --restart=Never -- env

{code}
is’t above command treat --restart=Never as part of container command

I would choose later one, that is more clear to me what is in the command

JohnC:
I guess the question is what are you trying to accomplish, if you want to see the output of the env command from the container the above wont do that - you’d use this:

kubectl exec busybox – env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=busybox
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
HOME=/root

Rahul:
@Mayur Sharma This works fine

Rahul:
@JohnC My question is - Just to execute any command we can use any approach ?

–command --env
OR
/bin/sh -c ‘env’

Just wanted to know if there any difference to kept in mind while using

JohnC:
i have always used

– /bin/sh -c env

format personally. Never had any issue with that in real life or on exams

JohnC:
Keep in mind that the image you use for the container will also have some effect so like in busybox you cant use

– /bin/bash

but on nginx you could for example

Ninad Desai:
Hi Rahul m in exam you can use based on whats been asked . For example if exam says command keyword then use ==> /bin/sh -c ‘command’ approach and if exam question refers to argument/args then==> use – ‘command’ approach . To remind,
what entrypoint command does in docker = what command does in k8s
and
what CMD does in docker = what args does in k8s

Mayur Sharma:
Thanks @Rahul and others, this is useful information!

Rahul:
Thank you all :slightly_smiling_face: Its clear now