Kubernetes: --image-pull-policy always does not work
If you are working with yml files, executing deployment with
kubectl apply -f myfile.yml
and
imagePullPolicy: Always
on your file, k8s will not pull a new image. You will first need to delete the pod, and the K8s deployment will automatically pull the image.
One way to force the update to happen is to run this in your CI script (after pushing the new image and with image-pull-policy
set to Always
in the applied yaml):
kubectl rollout restart deployment/<name> --namespace=<namespace>
In Azure Devops enter "rollout" as the command, use the namespace feature above and put "restart ..." in the parameters field.
Kubernetes is not watching for a new version of the image. The image pull policy specifies how to acquire the image to run the container. Always
means it will try to pull a new version each time it's starting a container. To see the update you'd need to delete the Pod (not the Deployment) - the newly created Pod will run the new image.
There is no direct way to have Kubernetes automatically update running containers with new images. This would be part of a continuous delivery system (perhaps using kubectl set image
with the new sha256sum or an image tag - but not latest
).