Hailu Meng:
Another verification on command and args: when using k run or exec, if no —command in place, the — only means the following is args. Correct? If there is —command, then the first element in the array is the command and the following elements in the array is args. Correct? But one confusion I have is why I only see things listed under command in yaml without seeing args when using —command in kubectl command with yaml output.
Alistair Mackay:
--command
will always populate the command array in the pod definition
Where you might want to use args
is based on how the container was built.
In a pod definition, command
overrides a container’s ENTRYPOINT
and args
overrides a container’s CMD
You need to know that more for CKAD
Alistair Mackay:
Remember, a command
will be an executable, optionally including its arguments. args
are further arguments that can be appended to cmd
.
KodeKloud CKAD course has a module on this.
Hailu Meng:
Thanks @Alistair Mackay . Understand the last statement. My confusion is more around when using —command in CLI with some args followed, why the yaml file doesn’t have the args array. I only see command array.
Alistair Mackay:
command:
- /bin/sh
- -c
- echo HI
Alistair Mackay:
is a command
Hailu Meng:
Should -c and - echo HI be listed as args in yaml?
Alistair Mackay:
Could also be expressed as
command:
- /bin/sh
args:
- -c
- echo HI
Hailu Meng:
Here we go, the last above is what I think yaml should be. But dryrun doesn’t produce this way.
Alistair Mackay:
But it is safe to put it all in command
. You really only need args
if you know the container has a CMD
block in its dockerfile that you need to override
Alistair Mackay:
command
is not synonymous with executable. It means more “command line”, so an executable with its arguments.
Hailu Meng:
I see your point here. It’s only recommended to use args when you know your Docker does have CMD block and you want to override. So everything under —command will replace ENTRYPOINT then. It’s same effect if you break it into command and args to replace ENTRY and CMD.
Alistair Mackay:
Yup
pod command
== docker ENTRYPOINT
Hailu Meng:
I think you cleared my confusion. I didn’t treat command plus args as command. I only thought executable as command.
Hailu Meng:
Also it’s better to have command in CLI if you don’t know what ENTRYPOINT is configured in Docker. Otherwise everything after — is treated as args by default and it won’t execute well if ENTRYPOINT doesn’t work with the args you define.