<p>I have defined a Deployment for my app:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: myapp-deployment
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: 172.20.34.206:5000/myapp_img:2.0
        ports:
        - containerPort: 8080
</code></pre>

<p>Now, if I want update my app's image 2.0 to 3.0, I do this:</p>

<ol>
<li><code>$ kubectl edit deployment/myapp-deployment</code></li>
<li><code>vim</code> is open. I change the image version from 2.0 to 3.0 and save.</li>
</ol>

<p>How can it be automated? Is there a way to do it just running a command? Something like:</p>

<pre><code>$ kubectl edit deployment/myapp-deployment --image=172.20.34.206:5000/myapp:img:3.0
</code></pre>

<p>I thought using Kubernetes API REST but I don't understand the <a href="https://htmlpreview.github.io/?https://github.com/kubernetes/kubernetes/blob/HEAD/docs/api-reference/extensions/v1beta1/operations.html" rel="noreferrer">documentation</a>. </p>

<p>You could do it via the REST API using the <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#patch-operations" rel="nofollow noreferrer">PATCH verb</a>. However, an easier way is to use <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#patch" rel="nofollow noreferrer">kubectl patch</a>. The following command updates your app's tag:</p>
<pre><code>kubectl patch deployment myapp-deployment -p \
  '{&quot;spec&quot;:{&quot;template&quot;:{&quot;spec&quot;:{&quot;containers&quot;:[{&quot;name&quot;:&quot;myapp&quot;,&quot;image&quot;:&quot;172.20.34.206:5000/myapp:img:3.0&quot;}]}}}}'
</code></pre>
<p>According to <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#patch" rel="nofollow noreferrer">the documentation</a>, YAML format should be accepted as well. See <a href="https://github.com/kubernetes/kubernetes.github.io/issues/458" rel="nofollow noreferrer">Kubernetes issue #458</a> though (and in particular <a href="https://github.com/kubernetes/kubernetes.github.io/issues/458#issuecomment-216371921" rel="nofollow noreferrer">this comment</a>) which may hint at a problem.</p>
