skip to Main Content

I created a docker image and uploaded it to Docker Hub.

My goal is that every time a pod is created, Openshift will pull the image from Docker Hub, while ignoring any cache it has.

I created a new app using the following command:

oc new-app --docker-image=docker.io/barak1412/docker_test:v1 --name=docker-test-app

And also changed the image pulling policy in the development YAML:

imagePullPolicy: Always

But still, Openshift keeps loading the image from somewhere in its internal cache, and as a result, the application is not updating.

Any suggestions?
Thanks.

2

Answers


  1. When you create an application using oc new-app, not only do you create a Deployment but in the background an ImageStream is configured as well. The application in the Deployment then references this ImageStream.

    So to update your Deployment do one of the following:

    • Edit your Deployment using oc edit deployment <name> and set the Docker Hub container image as the image.

    • Use oc get is to find the name of your ImageStream and then use oc import-image <name> to update it to the latest version. You can enable automatic updates by using --scheduled: Configuring periodic importing of image stream tags

    Login or Signup to reply.
  2. Setting this property imagePullPolicy: Always is the correct way. However, note that there is no way no you can disable the ImageStreams (internal cache) on OpenShift by default. The first time kubernetes pulled the image from the DockerHub, this image with the exact digest is cached. So the next time you try to pull, kubelet queries for the exact digest locally and pulls with the resolved digest.

    Always

    every time the kubelet launches a container, the kubelet queries the container image registry to resolve the name to an image digest. If the kubelet has a container image with that exact digest cached locally, the kubelet uses its cached image; otherwise, the kubelet pulls the image with the resolved digest, and uses that image to launch the container.

    If you want OpenShift to pull a new image from DockerHub:

    1. Push a new image to DockerHub with the same tag v1. This new image will have a new digest created by DockerHub itself.
    2. Now, delete the pod on your cluster.
    3. Since you’ve the ImagePullPolicy set to always, kubelet will first check local cache’s image (ImageStreams) and try to match with the new image and it’s digest value.
    4. Since the new image you pushed in step 1 has a different digest, kubelet will pull the new image from DockerHub, instead of pulling from the local cache

    Reference:
    https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search