<p>Why does <code>kubectl rollout restart &lt;deployment-name&gt;</code> doesn't get my latest image? I had rebuild my image but it seems that kubernetes doesn't update my deployment with the latest image.</p>

<h1 id="tldr-pznw">tl;dr</h1>
<p>I just wanted to add an answer here regarding the failure of <code>kubectl rollout restart deployment [my-deployment-name]</code>. My problem was that I <strong>changed the image name</strong>, without running <code>kubectl apply -f [my-deployment-filename&gt;.yaml</code> first.</p>
<h1 id="long-answer-iwu2">Long Answer</h1>
<p>So my earlier image name is <code>microservices/posts</code> which is in my local and looked like this.</p>
<pre class="lang-yaml prettyprint-override"><code># This is a file named `posts-depl.yaml`
apiVersion: apps/v1
kind: Deployment
metadata:
  name: posts-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: posts
  template:
    metadata:
      labels:
        app: posts
    spec:
      containers:
        - name: posts
          image: microservices/posts
</code></pre>
<p>However, since I need to push it to Docker Hub, I rebuild the image with a new name of <code>[my docker hub username]/microservices_posts</code> then I pushed. Then I updated the <code>posts-depl.yaml</code> to look like this.</p>
<pre class="lang-yaml prettyprint-override"><code># Still same file `posts-depl.yaml` but updated
apiVersion: apps/v1
kind: Deployment
metadata:
  name: posts-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: posts
  template:
    metadata:
      labels:
        app: posts
    spec:
      containers:
        - name: posts
          image: [my docker hub username]/microservices_posts # Notice that I only change this part
</code></pre>
<p>Apparently, when I ran <code>kubectl rollout restart deployment posts-depl</code>, it didn't update. Then I finally decided to go to StackOverflow. I just thought I had a wrong mistake or probably meet up with kubernetes bug or something.</p>
<p>But turns out I had to run <code>kubectl apply -f &lt;your deployment filename&gt;.yaml</code> again. Then it's running fine.</p>
<p>Just sharing, might change someone's life. ;)</p>
<p><strong>So for a review here..</strong></p>
<p>It seems that my past deployment which is <code>posts-depl</code> is cached with the image name of my earlier image which is <code>microservices/posts</code>, and since I build a new image named <code>[my docker hub username]/microservices_posts</code> it doesn't acknowledge that. So when I run <code>kubectl rollout restart deployment &lt;deployment name&gt;</code>. What it does instead was looking for the <code>microservices/posts</code> image which is on my local! But since it was not updated, it doesn't do a thing!</p>
<p>Hence, what I should be doing was re-running <code>kubectl apply -f &lt;my deployment filename&gt;.yaml</code> again which already has been updated with the new image name as  <code>[my docker hub username]/microservices_posts</code>!</p>
<p>Then, I live happily ever after.<br />
Hope that helps and may you live happily ever after too.</p>
