<p>I am trying to update my deployment with latest image content on Azure Kubernetes Service every time some code is committed to github . I have made a stage in my build pipeline to build and push the image on docker hub which is working perfectly fine. however in my release pipeline the image is being used as an artifact and is being deployed to the Azure Kubernetes Service , but the problem is that the image on AKS in not updating according to the image pushed on Docker Hub with latest code.</p>

<p>Right now each time some commit happens i have to manually update the image on AKS via the Command</p>

<p><em>kubectl set image deployment/demo-microservice demo-microservice=customerandcontact:contact</em> </p>

<p>My Yaml File</p>

<p><a href="https://i.stack.imgur.com/jAMCZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jAMCZ.png" alt="enter image description here"></a></p>

<p>Can anyone tell the error/changes if any in my yaml file to automatically update the image on AKS.</p>

Shubham Tiwari
<p>When you specify your image with the specific image tag Kubernetes will default container's <code>imagePullPolicy</code> to <code>IfNotPresent</code>, which means that image won't be pulled again, and previously pulled image will be deployed.</p>

<p>Kubernetes will change policy to <code>Always</code> only if tag is not present (which is effectively same as <code>latest</code> or if tag is set to <code>latest</code> explicitly.</p>

<p>Check what is actual imagePull policy on your Deployment template for particular container.</p>

<pre><code>kubectl get pod demo-microservice -o yaml | grep imagePullPolicy -A 1
</code></pre>

<p>Try patching deployment</p>

<pre><code>kubectl patch deployment demo-microservice -p 
 '{"spec": { "template" : 
  { "spec" : { "containers" : 
    [{"name" : "demo-microservice", 
    "image" : "repo/image:tag", 
    "imagePullPolicy": "Always" }]}}}}'
</code></pre>

<p>Make sure that <code>imagePullPolicy</code> for the container in question is set to <code>Always</code>.</p>
