<p>I have a file for a Job resource, which looks something like below.I need to run multiple instances with this definition with separate arguments for each.</p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  generateName: abc-
spec:
  template:
    spec:
      containers:
      - name: abc
        image: index.docker.io/some/image:latest
        imagePullPolicy: Always
      imagePullSecrets:
      - name: some_secret
      restartPolicy: Never
  backoffLimit: 4
</code></pre>

<p>I can successfully run this job resource with
<code>kubectl create -f my-job.yml</code>
But, I'm not sure how I pass my arguments corresponding to 
<strong>command:['arg1','arg2']</strong></p>

<p>I think updating the file with my dynamic args for each request is just messy.</p>

<p>I tried <code>kubectl patch -f my-job.yml --type='json' -p='[{"op": "add", "path": "/spec/template/spec/containers/0/", "value": {"command": ["arg1","arg2"] } }]'</code>, which works well for a Deployment kind but for Job it doesn't work</p>

<p>I tried
<code>sudo kubectl run  explicitly-provide-name-which-i-dont-want-to --image=index.docker.io/some/image:latest --restart=Never -- arg1 arg2</code>, but for this I won't be able to pass the <strong>imagePullSecrets</strong>.</p>

<p>kind of a generic answer here, just trying to guide you. In general what you express is the need to 'parameterize' your kubernetes deployment descriptors. There are different ways some are simple, some others are a bit hacky and finally there is <a href="https://github.com/kubernetes/helm" rel="nofollow noreferrer">github.com/kubernetes/helm</a>.</p>

<p>Personally I would strongly suggest you go through installing Helm on your cluster and then 'migrate' your job or any vanilla kubernetes deployment descriptor into a helm Chart. This will eventually give you the 'parameterization' power that you need to spin jobs in different ways and with different configs.</p>

<p>But, if this sounds like too much for you, I can recommend something that I was doing before I discover Helm. Using things like 'bash' / 'envsubst' I was eventually  - templating manually the parts of the yaml file, with place holders (e.g env variables) and then I was feedind the yaml to tools like 'envsubst' where they were replacing the placeholders with the values from the environment. Ugly? Yes. Maintenable? maybe for a couple of simple examples. Example of envsubst <a href="https://unix.stackexchange.com/questions/294378/replacing-only-specific-variables-with-envsubst">here</a>.</p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
spec:
  template:
    spec:
      containers:
      - name: abc
        image: index.docker.io/some/image:latest
        imagePullPolicy: Always
      imagePullSecrets:
      - name: $SOME_ENV_VALUE
      restartPolicy: Never
  backoffLimit: 4
</code></pre>

<p>Hope that helps..but seriously if you have time, consider checking 'Helm'.</p>
