How to repull image in kubernetes that is already cached? How to repull image in kubernetes that is already cached? kubernetes kubernetes

How to repull image in kubernetes that is already cached?


the best industry solution is to use a unique tag for each deployed image. change the image tag and k8s will handle the upgrade for you. you only have this problem because you want to use the same tag even though the image changes. Whatever the reason you think it's not worth explicitly versioning your image, you're wrong :P . Explicit versions are well work the effort of specifying them


u need to use Always in ImagePullPolicy. if so, whenever there is change in commit hash with a specific tag, K8S will pull again. Remember to set rollingUpdate too.


It depends if you are versioning your image on Docker Hub.

It's strongly encouraged to version your images for few reasons.

  • it's quicker to rollback in case of an issue, because you just change version number to previous

  • all your pods will use the same version of the image

You can read about configuration of Container Images in Kubernetes documentation.

The imagePullPolicy and the tag of the image affect when the kubelet attempts to pull the specified image.

  • imagePullPolicy: IfNotPresent: the image is pulled only if it is not already present locally.

  • imagePullPolicy: Always: the image is pulled every time the pod is started.

  • imagePullPolicy is omitted and either the image tag is :latest or it is omitted: Always is applied.

  • imagePullPolicy is omitted and the image tag is present but not :latest: IfNotPresent is applied.

  • imagePullPolicy: Never: the image is assumed to exist locally. No attempt is made to pull the image.

Note: To make sure the container always uses the same version of the image, you can specify its digest, for example sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2. The digest uniquely identifies a specific version of the image, so it is never updated by Kubernetes unless you change the digest value.

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.

Note: The caching semantics of the underlying image provider make even imagePullPolicy: Always efficient. With Docker, for example, if the image already exists, the pull attempt is fast because all image layers are cached and no image download is needed.