How to use rolling update to re-pull container ima

2019-07-06 16:55发布

问题:

I have a kubernetes RC/pod consisting of containers with images like: foobar/my-image:[branch]-latest where "branch" is the git branch ("master", etc).

What's the best way to use rolling-update to force the RC to re-pull the images to get the latest version? The brute force method is to simply delete the RC and re-create it, but that causes downtime for the service.

Is rolling update only possible if you specify an exact image tag, rather than something like "latest"?

回答1:

You should be able to use a rolling update specifying the same image name that you are currently using:

kubectl rolling-update <replication-controller-name> --image=foobar/myimage:[branch]-latest

This will (behind the scenes) create a new replication controller that is a copy of your existing replication controller with the "new" image, and then stepwise resize each of the replication controllers until the old one has zero pods and the new one has the desired number of pods, finally deleting the old one and renaming the new one to use the old name.



回答2:

If you want the rolling update to re-pull your image, you must either use the :latest tag or specify a image pull policy of Always (see Updating Images in the Kubernetes docs).

In your case, you can't use the :latest tag since you want the most recent image on a particular branch, so using the pull policy is the way to go.

dns-frontend-pod.yaml is an example file showing how to use the image pull policy of Always.