<p>I tried to use <code>kubectl patch</code> to add two more values to the args list of a kubernetes deployment. I've gone over the officially documented (<a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/" rel="noreferrer">https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/</a>) variants but did not manage to append more than one value at a time.</p>
<p>Assume this simple deployment:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
spec:
  replicas: 1
  selector:
    matchLabels:
      name: test
  template:
    metadata:
      labels:
        name: test
      name: test
    spec:
      containers:
      - image: alpine
        name: test
        command:
        - echo
        args:
        - my
        - text
</code></pre>
<p>I now want to append additional values to the <code>args</code> section. This works for a single value at a time:</p>
<h3>Adding a single additional value</h3>
<pre class="lang-sh prettyprint-override"><code>kubectl patch deployments.apps test --type=json -p='[{&quot;op&quot;: &quot;add&quot;, &quot;path&quot;: &quot;/spec/t
emplate/spec/containers/0/args/-&quot;, &quot;value&quot;: &quot;additional&quot; }]'
</code></pre>
<p>This works and leaves me with the following:</p>
<pre class="lang-yaml prettyprint-override"><code>...
        args:
        - my
        - text
        - additional
</code></pre>
<p>But running the patch with an array of values gives me an error:</p>
<pre class="lang-sh prettyprint-override"><code># running:
k patch deployments.apps test --type=json -p='[{&quot;op&quot;: &quot;add&quot;, &quot;path&quot;: &quot;/spec/template/spec/containers/0/args/-&quot;, &quot;value&quot;: [&quot;additional&quot;,&quot;text&quot;] }]'

# results in:
The request is invalid: patch: Invalid value: &quot;...&quot;: v1.Deployment.Spec: v1.DeploymentSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.Containers: []v1.Container: v1.Container.Args: []string: ReadString: expects &quot; or n, but found [, error found in #10 byte of ...|itional&quot;,[&quot;additiona|..., bigger context ...|{&quot;containers&quot;:[{&quot;args&quot;:[&quot;my&quot;,&quot;text&quot;,&quot;additional&quot;,[&quot;additional&quot;,&quot;text&quot;]],&quot;command&quot;:[&quot;echo&quot;],&quot;image&quot;:&quot;|...
</code></pre>
<p>Does anyone know a way to add mutliple values to an array within a single patch command without overwriting the whole args array? Thanks for your help.</p>

<p>Below uses a single patch but it's not very DRY:</p>
<pre><code>kubectl patch deployment &lt;deployment-name&gt; -n &lt;namespace&gt; --type &quot;json&quot; -p '[
{&quot;op&quot;:&quot;add&quot;,&quot;path&quot;:&quot;/spec/template/spec/containers/0/args/-&quot;,&quot;value&quot;:&quot;arg-1&quot;},
{&quot;op&quot;:&quot;add&quot;,&quot;path&quot;:&quot;/spec/template/spec/containers/0/args/-&quot;,&quot;value&quot;:&quot;arg-2&quot;},
{&quot;op&quot;:&quot;add&quot;,&quot;path&quot;:&quot;/spec/template/spec/containers/0/args/-&quot;,&quot;value&quot;:&quot;arg-3&quot;}]'
</code></pre>
<p>I've been doing something similar for <a href="https://cert-manager.io/v0.15-docs/usage/ingress/#optional-configuration" rel="noreferrer">cert-manager</a> to allow fully automated TLS:</p>
<pre><code>kubectl patch deployment cert-manager -n cert-manager --type &quot;json&quot; -p '[
{&quot;op&quot;:&quot;add&quot;,&quot;path&quot;:&quot;/spec/template/spec/containers/0/args/-&quot;,&quot;value&quot;:&quot;--default-issuer-name=letsencrypt-prod&quot;},
{&quot;op&quot;:&quot;add&quot;,&quot;path&quot;:&quot;/spec/template/spec/containers/0/args/-&quot;,&quot;value&quot;:&quot;--default-issuer-kind=ClusterIssuer&quot;},
{&quot;op&quot;:&quot;add&quot;,&quot;path&quot;:&quot;/spec/template/spec/containers/0/args/-&quot;,&quot;value&quot;:&quot;--default-issuer-group=cert-manager.io&quot;}]'
</code></pre>
