Alexander Mills
Alexander Mills

Reputation: 99960

Redeploy latest image without using `kubectl apply -f file`

We have a deployment on a cluster, we want to tell it to pull the latest image and re-deploy. If I run kubectl apply -f deployment.yml that file hasn't actually changed. How do I just tell the cluster to use a newer image version?

Upvotes: 0

Views: 968

Answers (1)

Mark
Mark

Reputation: 4067

As per documentation:

Note: A Deployment’s rollout is triggered if and only if the Deployment’s pod template (that is, .spec.template) is changed, for example if the labels or container images of the template are updated. Other updates, such as scaling the Deployment, do not trigger a rollout.

Please consider using:

kubectl patch deployment my-nginx --patch '{"spec": {"template": {"spec": {"containers": [{"name": "nginx","image": "nginx:1.7.9"}]}}}}'
    
kubectl --record deployment.apps/nginx-deployment set image deployment.v1.apps/nginx-deployment nginx=nginx:1.9.1
    
kubectl edit deploy/<your_deployment> --record

Documentation about Updating a Deployment and Container Images.

According to the best practices please Note:

You should avoid using the :latest tag when deploying containers in production as it is harder to track which version of the image is running and more difficult to roll back properly.

However if you would like always force pull new image you can use on of those options:

   - set the imagePullPolicy of the container to Always.
   - omit the imagePullPolicy and use :latest as the tag for the image to use.
   - omit the imagePullPolicy and the tag for the image to use.
   - enable the AlwaysPullImages admission controller.

Hope this help.

Upvotes: 1

Related Questions