Command in Kubernetes

Hi, I would like to ask about the command section in a pod or a job:

I see different versions of commands that are somehow confusing.

To be specific:

command: [“/bin/sh”, “-c”, “ps -eaf”]

or

command: [“date”].

Could not we write command: [“/bin/sh”, “-c”, “date”] ?

To my knowledge /bin/sh opens a new bash shell in the container of a pod.
Could we in short simply write command: [“date”]?


or the other way with args is also a little bit confusing:

containers:
- args:
** - /bin/sh**
** - -c**
** - echo hello;sleep 3600**
image: busybox
imagePullPolicy: IfNotPresent
name: busybox
resources: {}
- args:
** - /bin/sh**
** - -c**
** - echo hello;sleep 3600**
image: busybox
name: busybox2

Is somewhere only possible to use args instead of the “command” that seem to be more readable?

Since you can launch commands without a shell on Linux, any command that does not need a shell can be launched using something like

command:
- date

You can also use a shell for this, but there’s no reason to do that.

You might need to use a shell if you’re using the features of a shell. this requires it, for example:

command:
- sh
- -c
- echo hello; sleep 3600

As for command vs args: this depends upon how the container is set up with CMD and ENTRYPOINT. Sometimes you can use either, depending upon what those are for the container.