<p>If I run the <code>kubectl create -f deployment.yaml</code> command with
the following <code>deployment.yaml</code> file, everything succeeds.</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
 name: my_app
 labels:
  app: my_app
spec:
 containers:
  - name: my_app
    image: docker:5000/path_to_my_custom_image
    args: ["my_special_argument"]
</code></pre>

<p>However, now I want to have a custom "my_special_argument"
as follows</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
 name: my_app
 labels:
  app: my_app
spec:
 containers:
  - name: my_app
    image: docker:5000/path_to_my_custom_image
    args: ["$(ARG)"]
</code></pre>

<p>and I want to somehow set the value of $ARG$ when I execute the <code>kubectl create -f deployment.yaml</code> command. How to do that?</p>

<p>I am looking for something like:
<code>kubectl create -f deployment.yaml --ARG=new_arg</code></p>

<p>Can such command be executed?</p>

<p>You can use Environment variables in the <code>deployment.yaml</code></p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
 name: my_app
 labels:
  app: my_app
spec:
 containers:
  - name: my_app
    image: docker:5000/path_to_my_custom_image
    env:
    - name: SPECIAL_ARG_VAL
      value: "my_special_argument_val_for_my_app"
    args: ["$(SPECIAL_ARG_VAL)"]

</code></pre>

<p>Also, you can load the value for environment variables using Secrets or Configmaps.</p>

<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#configure-all-key-value-pairs-in-a-configmap-as-container-environment-variables" rel="nofollow noreferrer">Here</a> is an example loading value from configmap</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
 name: my_app
 labels:
  app: my_app
spec:
 containers:
  - name: my_app
    image: docker:5000/path_to_my_custom_image
    env:
    - name: SPECIAL_ARG_VAL
      valueFrom:
        configMapKeyRef:
          name: special-config
          key: SPECIAL_VAL_KEY
    args: ["$(SPECIAL_ARG_VAL)"]
</code></pre>

<p>You can create the configmap using <code>kubectl</code> as the following, but recommend to have a separate yaml file.</p>

<pre><code>kubectl create configmap special-config --from-literal=SPECIAL_VAL_KEY=my_special_argument_val_for_my_app
</code></pre>

<p>You can even remove the <code>args</code> from the pod yaml above if you had the same environment variable defined in the Dockerfile for the image.</p>
