1

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?

David Maze
  • 130,717
  • 29
  • 175
  • 215
Kirill
  • 23
  • 3
  • 2
    Have you set `imagePullPolicy: Always`? – zerkms May 13 '20 at 09:51
  • As follows from [here](https://stackoverflow.com/questions/45905999/kubernetes-image-pull-policy-always-does-not-work) ```imagePullPolicy: Always``` worked not as expected. Finally ```There is no direct way to have Kubernetes automatically update running containers with new images.``` Following [documentation](https://kubernetes.io/docs/concepts/containers/images/) really disappointing me – Kirill May 13 '20 at 10:26
  • 1
    Since the image name isn't changing, you're not actually changing anything in the Deployment object, so the cluster concludes everything is in the state you want it to be in (you want an image name called `registry/service-name:branch` and that's the image the pods are running). If you use a unique tag per build this won't be a problem. – David Maze May 13 '20 at 10:56
  • Unfortunately changing label is not my way because environment consists of tens of microservices and should build from branch with last changes which means - on each push/commit. But foregoing link which you provide describes three workable tricks which resolve my problem and one of them (adding random terminationGracePeriodSecond value) I checked and it looks like solution. Thank you @DavidMaze! – Kirill May 13 '20 at 15:22

1 Answers1

1

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
  • 3,007
  • 2
  • 19
  • 35