# Command and Args fields

**URL:** <https://discuss.kubernetes.io/t/command-and-args-fields/11589>\
**Category:** General Discussions\
**Created:** [June 24, 2020, 1:53pm UTC](https://discuss.kubernetes.io/t/command-and-args-fields/11589 "2020-06-24T13:53:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![cetiberiojr](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/cetiberiojr/32/5071_2.png) [@cetiberiojr](https://discuss.kubernetes.io/u/cetiberiojr)\
**Post date:** [June 24, 2020, 1:53pm UTC](https://discuss.kubernetes.io/t/command-and-args-fields/11589/1 "2020-06-24T13:53:30Z")

</div>

Hi Guys,

I read all the documentation we have about the Command and Args fields inside our .yaml files  
I know what they do, what they substitute in the image itself and so on…

I saw we have another ways to list the args fields as well, not only using …

The bigger question is, what is the difference between:

args: [“some arg”]

args:

- “some arg”
- …

And my next question and what is causing more trouble to me is:

I have my binary inside the image and I’m trying a lot of ways to start him (he has a lot of parameters):

command: [“myBinary”]

args: ["-f -n -s"] or  
args:

- “-f -n -s”

And the strange thing is, this is not working, my binary keeps telling me the parameters are wrong, but if I start it directly using:

kubectl exec myPod – myBinary -f -n -s

it WORKS!

So I have some doubts about how this args really works…

If I want to start myBinary with just one line (putting all the parameters there) I need to start it using shell? I cannot do it directly?

Thanks!

---

<div class="post-metadata">

**Author:** ![stephendotcarter](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/stephendotcarter/32/4528_2.png) [@stephendotcarter](https://discuss.kubernetes.io/u/stephendotcarter)\
**Post date:** [June 24, 2020, 2:14pm UTC](https://discuss.kubernetes.io/t/command-and-args-fields/11589/2 "2020-06-24T14:14:47Z")

</div>

> [@cetiberiojr](#):
>
> The bigger question is, what is the difference between:
> 
> args: [“some arg”]
> 
> args:
> 
> - “some arg”
> - …

This is just different YAML syntax which means the same thing. Either is OK.

I think your problem is each argument needs to be a separate entry like this:

```auto
args:
- "-f"
- "-n"
- "-s"

```

or

```auto
args: ["-f", "-n", "-s"]

```

Kind regards,  
Stephen

---

<div class="post-metadata">

**Author:** ![cetiberiojr](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/cetiberiojr/32/5071_2.png) [@cetiberiojr](https://discuss.kubernetes.io/u/cetiberiojr)\
**Post date:** [June 24, 2020, 3:03pm UTC](https://discuss.kubernetes.io/t/command-and-args-fields/11589/3 "2020-06-24T15:03:50Z")

</div>

> [@stephendotcarter](#):
>
> ```auto
> args:
> - "-f"
> - "-n"
> - "-s"
> 
> ```
> 
> or
> 
> ```auto
> args: ["-f", "-n", "-s"]
> 
> ```

Ok, so if my parameter has a value as well, like:

-f 5 -n -s 0

It should be all space by space? “-f”, “5”, “-n”, “-s”, “0”?

Because as I’m expanding this as a helm chart, I’m exposing it to the values.yaml, and wanted to write it direct as “-f 5 -n -s 0”…

Maybe I’ll need to do some trick to cut it string by string? hehe

---

<div class="post-metadata">

**Author:** ![thockin](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/thockin/32/2457_2.png) [@thockin](https://discuss.kubernetes.io/u/thockin)\
**Post date:** [June 24, 2020, 3:30pm UTC](https://discuss.kubernetes.io/t/command-and-args-fields/11589/4 "2020-06-24T15:30:57Z")

</div>

Args is a list, which is passed into your app as argv or os.Args or  
whatever your language uses to parse the commandline. Most  
commandline processing libs (not all) support [“-f”, “5”] as well as  
[“-f5”] or [“-f=5”], but you can’t just string multiple flags  
together in one string.

---

<div class="post-metadata">

**Author:** ![cetiberiojr](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/cetiberiojr/32/5071_2.png) [@cetiberiojr](https://discuss.kubernetes.io/u/cetiberiojr)\
**Post date:** [June 24, 2020, 3:34pm UTC](https://discuss.kubernetes.io/t/command-and-args-fields/11589/5 "2020-06-24T15:34:15Z")

</div>

Hmmm, got you! so it’s not 100% only k8s, it depends as well how my binary is using the args!  
I’m using C++ by the way, but I’ll do some tests with this new discovery and will return if I have more problems…

---

<div class="post-metadata">

**Author:** ![thockin](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/thockin/32/2457_2.png) [@thockin](https://discuss.kubernetes.io/u/thockin)\
**Post date:** [June 24, 2020, 5:32pm UTC](https://discuss.kubernetes.io/t/command-and-args-fields/11589/6 "2020-06-24T17:32:34Z")

</div>

C++ brings args in to `main()` as `main(int argc, char *argv[])`, so each k8s `args` item is one element of `argv`. When you call your app on the commandline, the shell parses your “-f 5 -n -s 0” into “words” which it passes to the binary. k8s doesn’t impose a shell, and doesn’t try to parse shell-like commandline (quoting rules are hard and vary between shells, for example).

One cheap alternative, if you have a shell in your image is to run `command: [`sh`], args: [`-c`, `"myapp -f 5 -n -s 0”]`, but as I said that requires a shell.

---

<div class="post-metadata">

**Author:** ![cetiberiojr](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/cetiberiojr/32/5071_2.png) [@cetiberiojr](https://discuss.kubernetes.io/u/cetiberiojr)\
**Post date:** [June 24, 2020, 6:31pm UTC](https://discuss.kubernetes.io/t/command-and-args-fields/11589/7 "2020-06-24T18:31:01Z")

</div>

Yes, this is something that I was thinking…

But then I was having another problem with this approach (I stopped using shell because of this)…

The problem I was having were:  
When I was testing the pod shutdown (killing it using k8s delete or helm del) the SIGTERM wasn’t being sent to my application (as the documentation suggest we should have in the ending lifecycle) causing my binary to not shutdown gracefully…

So I changed to use the binary direct in commands/args to have it working (as I understood k8s wasn’t sending SIGTERM to my binary because it was sending to the shell as it was the first thing started…)

And then, I came here for this args things, hehe

---

<div class="post-metadata">

**Author:** ![thockin](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/thockin/32/2457_2.png) [@thockin](https://discuss.kubernetes.io/u/thockin)\
**Post date:** [June 24, 2020, 6:47pm UTC](https://discuss.kubernetes.io/t/command-and-args-fields/11589/8 "2020-06-24T18:47:07Z")

</div>

Yes, this is probably correct. Shell and signals are not great friends. You could run “sh”, “-c”, “exec mycommand -f 5 -n -s 0”, but I think you’re better off fixing the real problem 🙂

---

<div class="post-metadata">

**Author:** ![geekbot](https://avatars.discourse-cdn.com/v4/letter/g/eada6e/32.png) [@geekbot](https://discuss.kubernetes.io/u/geekbot)\
**Post date:** [June 25, 2020, 11:01am UTC](https://discuss.kubernetes.io/t/command-and-args-fields/11589/9 "2020-06-25T11:01:42Z")

</div>

This video helps me : [https://www.youtube.com/watch?v=OYbEWUbmk90](https://www.youtube.com/watch?v=OYbEWUbmk90)  
HTH

---

<div class="post-metadata">

**Author:** ![cks\_s](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/cks_s/32/7277_2.png) [@cks\_s](https://discuss.kubernetes.io/u/cks_s)\
**Post date:** [March 28, 2021, 7:14pm UTC](https://discuss.kubernetes.io/t/command-and-args-fields/11589/10 "2021-03-28T19:14:50Z")

</div>

args: ["–demo 45 -S"] this is another example of arguments: --demo 45 -S
