<p>Create one liner (Imperative way) command in kubernetes</p>
<pre><code>kubectl run test --image=ubuntu:latest --limits=&quot;cpu=200m,memory=512Mi&quot; --requests=&quot;cpu=200m,memory=512Mi&quot; --privileged=false
</code></pre>
<p>And also I need to set <code>securityContext</code> in one liner, is it possible? basically I need to run container as <code>securityContext/runAsUser</code> not as <code>root</code> account.</p>
<p>Yes declarative works, but I'm looking for an imperative way.</p>

Manjunath v
<p>Posting this answer as a community wiki to highlight the fact that the solution was posted in the comments (a link to another answer):</p>
<blockquote>
<p>Hi, check this answer: <a href="https://stackoverflow.com/a/37621761/5747959">stackoverflow.com/a/37621761/5747959</a> you can solve this with --overrides – CLNRMN 2 days ago</p>
</blockquote>
<p>Feel free to edit/expand.</p>
<hr />
<p>Citing <code>$ kubectl run --help</code>:</p>
<blockquote>
<pre><code>  --overrides='': An inline JSON override for the generated object. If this is non-empty, it is used to override the generated object. Requires that the object supply a valid apiVersion field.
</code></pre>
</blockquote>
<p>Following on <code>--overrides</code> example that have additionals field included and to be more specific to this particular question (<code>securityContext</code> wise):</p>
<pre class="lang-sh prettyprint-override"><code>kubectl run -it ubuntu --rm --overrides='
{
  &quot;apiVersion&quot;: &quot;v1&quot;,
  &quot;spec&quot;: {
    &quot;securityContext&quot;: {
      &quot;runAsNonRoot&quot;: true,
      &quot;runAsUser&quot;: 1000,
      &quot;runAsGroup&quot;: 1000,
      &quot;fsGroup&quot;: 1000
    },
    &quot;containers&quot;: [
      {
        &quot;name&quot;: &quot;ubuntu&quot;,
        &quot;image&quot;: &quot;ubuntu&quot;,
        &quot;stdin&quot;: true,
        &quot;stdinOnce&quot;: true,
        &quot;tty&quot;: true,
        &quot;securityContext&quot;: {
          &quot;allowPrivilegeEscalation&quot;: false
        }
      }
    ]
  }
}
' --image=ubuntu --restart=Never -- bash
</code></pre>
<p>By above override you will use a <code>securityContext</code> to constrain your workload.</p>
<blockquote>
<p>Side notes!</p>
<ul>
<li>The example above is specific to running a <code>Pod</code> that you will exec into (<code>bash</code>)</li>
<li>The <code>--overrides</code> will override the other specified parameters outside of it (for example: <code>image</code>)</li>
</ul>
</blockquote>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://kubernetes.io/docs/tasks/configure-pod-container/security-context/" rel="nofollow noreferrer">Kubernetes.io: Docs: Tasks: Configure pod container: Security context</a></em></li>
<li><em><a href="https://kubernetes.io/docs/concepts/security/pod-security-standards/" rel="nofollow noreferrer">Kubernetes.io: Docs: Concepts: Security: Pod security standards</a></em></li>
</ul>
