<p>I want to pass arguments to Kubernetes deployment when I use <code>kubectl</code> command to apply the deployment file.</p>
<p>Example: In my deployment .yaml, I have arguments as below and I want to pass the argument values when I run with the <code>kubectl apply - f &lt;my-deployment&gt;.yaml</code></p>
<p>So, in the below example, I want to override the args - userid and role when I run the above kubectl command.</p>
<pre><code>spec:
      containers:
        - name: testimage
          image: &lt;my image name&gt;:&lt;tag&gt;
          args:
          - --userid=testuser
          - --role=manager
</code></pre>

<p>The simple answer is. You can't do that.</p>

<p><code>kubectl</code> is not a template engine. As some people mentioned, you have options like Helm or Kustomize which can solve this. I'd encurage you to look into Helm3 since it nicely solves your problem with a command like <code>helm upgrade --install ... --set userid=xxx --set role=yyy</code>.</p>

<p>If you're stuck with kubectl only though, you might want to use it's ability to ingest yaml from stdin and pass your yaml through any type of templating first. ie. as follows :</p>

<pre><code>...
args:
- --userid=$USER
- --role=$ROLE
...
</code></pre>

<pre><code>cat resource.yaml | USER=testuser ROLE=manager envsubst | kubectl apply -f -
</code></pre>

<p>obviously any other string replacement method would do (sed, awk, etc.)</p>
