Hi, How can we pass both command and arguments in kubectl run command. When I ru . . .

pikachunetes:
Hi,
How can we pass both command and arguments in kubectl run command.
When I run the below command:
k run secret-test-pod --image=<http://k8s.gcr.io/busybox|k8s.gcr.io/busybox> --dry-run=client -o yaml --command -- /bin/sh -c env
it only adds to the command parameters
The resultant yaml file is like this:

apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: secret-test-pod
name: secret-test-pod
spec:
containers:


unnivkn:
Hi… in this command: --command – /bin/sh -c env you are passing env as an argument

pikachunetes:
Hi @unnivkn, but as you can see the produced YAML file from this command
there is no args section
so how can produce both command and args parameters in a pod spec via an imperative command

unnivkn:
good question… not sure we have that option… need to investigate

Madhan Kumar:
By default the first word is considered as the command and the words that come after are considered as its args . I could not think of a reason why we need to pass commands and args separately in the yaml , because once you pass a command in yaml with or without args it overrides both the entrypoint and command defined in the docker file . so just using a multi word command is good enough . https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/

Madhan Kumar:
kubectl run --help # to see the examples

Madhan Kumar:
both the below examples gives you the same result …

command: ["/bin/sh"]
args: ["-c", “while true; do echo hello; sleep 10;done”]

command: ["/bin/sh", “-c”, “while true; do echo hello; sleep 10;done”]

Madhan Kumar:

pikachunetes:
Thanks @Madhan Kumar, understood