<p>I'm working on a question that wants me to deploy a pod with the <code>nginx</code> image. The pod should sleep for 5000 seconds.</p>
<p>The command can be specified like so:</p>
<pre><code>command: [&quot;sleep&quot;, &quot;5000&quot;]
</code></pre>
<p>or like so:</p>
<pre><code>command:
  - sleep
  - &quot;5000&quot;
</code></pre>
<p>Why can't the command be specified like so:</p>
<pre><code>command:
  - sh
  - -c
  - sleep &quot;5000&quot;
</code></pre>
<p>or like so:</p>
<pre><code>command:
  - sleep &quot;5000&quot;
</code></pre>
<p>In other words, I'm confused about two things:</p>
<ol>
<li>What does <code>sh -c</code> do? I understand that <code>-c</code> is there to denote arguments, but isn't the <code>sleep</code> command run using <code>sh</code>?</li>
<li>When can the command and args be listed on the same line, and when do they have to be on separate lines? In this example, why doesn't <code>sleep &quot;5000&quot;</code> work? Why do <code>sleep</code> and <code>&quot;5000&quot;</code> have to be on separate lines? Also, why are quotes around the number 5000 required?</li>
</ol>

powerful_clouds
<p>Note that <code>command</code> and <code>args</code> as in K8s object definitions or manifest are in-facet <code>entrypoint</code> and <code>cmd</code> fields as found in container image definitions. These are supposed to behave in a certain specific way. for eg: if you look at at how docker images are defined, you would find <code>entrypoint</code> and <code>cmd</code> as 2 highly used fields.</p>
<p>supplying <code>command</code> and/or <code>args</code> in K8s object definition overrides <code>entrypoint</code> and <code>cmd</code> fields of the associated container.</p>
<p><code>entrypoint</code> in docker image definitions for example is allowed either as a single string (<code>sleep 5000</code>) or as a broken down array ([&quot;sleep&quot;, &quot;500&quot;]). either ways, it's eventually broken down into an array of arguments (i.e. <code>sleep 5000</code> becomes [&quot;sleep&quot;, &quot;5000&quot;]).</p>
<p><strong>I suppose K8s tries to simplify this by letting you supply this only as an array</strong>.</p>
<p>this <a href="https://aws.amazon.com/blogs/opensource/demystifying-entrypoint-cmd-docker/" rel="nofollow noreferrer">article</a> is a good reference to understand how <code>entrypoint</code> and <code>cmd</code> work in combination on container image definitions. The behavior feels a bit unnecessarily complicated and I cannot thank K8s contributors more for they simplified it to some extent at least.</p>
