<p>Is it possible to modify a live Kubernetes manifest, on-the-fly and non-interactively? I know <code>kubectl edit</code> allows for this behavior, but this requires user interaction in an editor that is opened when the command is invoked. I need to be able to do this without user interaction (for example in a script, etc.). Is this possible with a simple command - perhaps a variation of <code>kubectl edit</code>?</p>

Joseph Gagnon
<p>The Answer is <code>kubectl patch</code> (<a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/" rel="nofollow noreferrer">docs</a>).</p>
<p>For example, Given a deployment you can for example update the <code>.spec.template.spec.containers[].image</code> field using the following command:</p>
<pre class="lang-bash prettyprint-override"><code>kubectl patch deployment my-deploy \
  --patch '{&quot;spec&quot;: {&quot;template&quot;: {&quot;spec&quot;: {&quot;containers&quot;: [{&quot;image&quot;: &quot;nginx:1.12.5&quot;}]}}}}'
</code></pre>
<p>This way, you only specify the fields of the object that have changed. You may also pass a file with the changed fields instead of inline json, eg:</p>
<pre class="lang-bash prettyprint-override"><code>cat ./patch.yaml
spec:
  template:
    spec:
      containers:
        - image: nginx:1.12.5

kubectl patch deployment my-deploy --patch-file ./patch.yaml
</code></pre>
<p>Both versions support <code>json</code> and <code>yaml</code> to specify the changeset.</p>
