简体   繁体   中英

kubectl rollout restart deployment <deployment-name> doesn't get the latest image

Why does kubectl rollout restart <deployment-name> 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.

tl;dr

I just wanted to add an answer here regarding the failure of kubectl rollout restart deployment [my-deployment-name] . My problem was that I changed the image name , without running kubectl apply -f [my-deployment-filename>.yaml first.

Long Answer

So my earlier image name is microservices/posts which is in my local and looked like this.

# 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

However, since I need to push it to Docker Hub, I rebuild the image with a new name of [my docker hub username]/microservices_posts then I pushed. Then I updated the posts-depl.yaml to look like this.

# 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

Apparently, when I ran kubectl rollout restart deployment posts-depl , 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.

But turns out I had to run kubectl apply -f <your deployment filename>.yaml again. Then it's running fine.

Just sharing, might change someone's life. ;)

So for a review here..

It seems that my past deployment which is posts-depl is cached with the image name of my earlier image which is microservices/posts , and since I build a new image named [my docker hub username]/microservices_posts it doesn't acknowledge that. So when I run kubectl rollout restart deployment <deployment name> . What it does instead was looking for the microservices/posts image which is on my local! But since it was not updated, it doesn't do a thing!

Hence, what I should be doing was re-running kubectl apply -f <my deployment filename>.yaml again which already has been updated with the new image name as [my docker hub username]/microservices_posts !

Then, I live happily ever after.
Hope that helps and may you live happily ever after too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM