How can I force Kubernetes to re-pull an image?

In Kubernetes, images are used to deploy and manage containerized applications. An image serves as a self-contained package that includes all the necessary dependencies and configurations required to run an application. When deploying an application, Kubernetes pulls the specified image from a container registry, creating and running containers based on that image.

However, there are scenarios where you need to force Kubernetes to re-pull an image, such as:

  • When an updated version of the image becomes available.

  • To ensure that the latest changes in the image are applied.

  • When there are critical security updates in the image.

  • After modifying the image's configuration or dependencies.

  • To synchronize the image across multiple clusters or nodes.

Forcing Kubernetes to Re-Pull an Image:

To force Kubernetes to re-pull an image, you can use the following approaches.

  • Change the image pull policy: Set the imagePullPolicy of the Kubernetes Deployment or Pod to Always. This ensures that Kubernetes always attempts to pull the latest image version, even if it already has a copy of the image locally. Update the Deployment or Pod manifestRefers to the YAML configuration. with the following configuration:

spec:
containers:
- name: your-container
image: your-image:tag
imagePullPolicy: Always
  • Update the image tag: Another way to force Kubernetes to re-pull an image is to update the image tag. When you update the tag, Kubernetes recognizes it as a new image and will pull the updated version. Here's an example of how you can update the image tag in a Kubernetes Deployment manifest:

apiVersion: apps/v1
kind: Deployment
metadata:
name: your-deployment
spec:
replicas: 1
selector:
matchLabels:
app: your-app
template:
metadata:
labels:
app: your-app
spec:
containers:
- name: your-container
image: your-image:old-tag
# Optional: Set the image pull policy to "Always" as explained in the previous section.
imagePullPolicy: Always

Note: To force Kubernetes to re-pull the image, you need to update the your-image:old-tag portion with the new image tag. Once you make this change and "apply" the updated Deployment manifest, Kubernetes will recognize it as a new image reference and pull the updated version.

  • Rolling Update: Kubernetes supports rolling updates, allowing gradual application deployment updates. It creates a new replica set with the updated image while scaling down the old replica set, ensuring all instances use the latest image version. Rolling updates provide the flexibility to revert to the previous version if any issues occur during the update process. if you are using a Deployment, you can trigger a rolling update by updating the Deployment's .spec.template section. Changing any value in the template causes Kubernetes to create new Pods with the updated image. For example:

kubectl set image deployment/your-deployment your-container=your-image:tag
Command to trigger rolling updates

The kubectl set image command above updates the image of a container within a Kubernetes Deployment. It triggers a rolling update, creating new Pods with the updated image and gradually terminating the old Pods for seamless transition and minimal downtime.

Note: Make sure to replace your-deployment, your-app, your-container, your-image, and old-tag with the appropriate names and tags for your specific deployment.

Conclusion

Hence, by following one of the above-mentioned methods, you can allow you Kubernetes to re-pull an image.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved