Kubernetes not updates Docker image on redeployment

5/13/2020

Automation builds Docker image with microservice and push this image into JFrog Artifactory registry labeled by branch name registry/service-name:branch. At the next step it applies Kubernetes yaml manifest file and application starts after pulling image at the appropriate Kubernetes node. The problem is following - when I push changes in microservice source code into repository the automation starts:

  • rebuild the project and push updated docker image into registry with the same label(branch)
  • redeploy the microservice in Kubernetes
  • microservice redeployed but with old image

I guess it is occurs because there are no changes in 'Deployment' section of Kubernetes yaml manifest file and Kubernetes not pull updated image from JFrog registry. As workaround, I implement inserting timestamp annotation into template section on each redeployment:

  "template": {
      "metadata": {
          "labels": {
              "app": "service-name"
          },
          "annotations": {
              "timestamp": "1588246422"

But miracle is not happened - image updated only when I delete Kubernetes deployment and redeploy the application (may be in this case it just starts at the another node and docker pull is necessary).

Is it possible to setup Kubernetes or configure manifest file some how to force Kubernetes pull image on each redeployment?

-- Kirill
kubernetes

1 Answer

5/13/2020

I would suggest labeling the images in the pattern of registry/service-name:branch-git-sha or registry/service-name:git-sha which will pull the images automatically.

Or as a workaround, you can keep the current image labeling system and add an environment variable in the template which gets sets to the timestamp.

Changing the environment variable will always result in the restarting of the pods along with the config imagePullPolicy: Always.

-- Tummala Dhanvi
Source: StackOverflow