0

I'm trying to build a Jenkins CICD pipeline with Minikube, I just had a question regarding pulling the most recently built image from Dockerhub onto the K8s cluster.

In jenkins I'm using %BUILD_NUMBER% to generate a numeric tag for each image being built, the issue comes in when I want to pull the most recent image version in my K8s deployment definition.

This is one of my stages in the Jenkins pipeline to generate a tag for the images

bat 'docker push %docker_username%/devops-integration:%BUILD_NUMBER%'

In my Deployment definition

      - name: spring-boot-kubernetes
          image: test/devops-integration:36 # I would like the most recent version from dockerhub
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080

If i even try to pull the :latest image manually I get this error:

Error response from daemon: manifest for test/devops-integration:latest not found: manifest unknown: manifest unknown

I would like to pull the most recent image in my Deployment but unsure how to do this, I can specify a previous version of my image but that's not what I would like. Can anyone let me know how to get this working please.

ServletException
  • 171
  • 1
  • 15
  • Does a setup like [Helm Set Docker Image Tag Dynamically](https://stackoverflow.com/questions/59731397/helm-set-docker-image-tag-dynamically) help? Or [Kubernetes how to make Deployment to update image](https://stackoverflow.com/questions/40366192/kubernetes-how-to-make-deployment-to-update-image) (I'd prefer the options in its answers that update the `image:` over imperative restarts)? – David Maze Aug 31 '22 at 22:37

1 Answers1

-1

You could tag your images with "latest" and then use :latest tag. You can always add multiple tags. If your registry allows moving tags, using "latest" as tag on the latest build works.

But beware if you do this on multiple branches, you will not know which one you are using.

Adam Malik
  • 345
  • 1
  • 7
  • A `...:latest` tag doesn't work reliably in Kubernetes. If a node already has a copy of an image, it won't pull it again, so you can wind up with different "latests" on different nodes; also, the Deployment mechanism depends on the literal string value of the `image:` changing to trigger an update, so your CD system will have trouble causing the cluster to deploy a new build. – David Maze Aug 31 '22 at 22:33
  • Thats true. He should query the latest tag in ci/cd and inject it as a variable. – Adam Malik Aug 31 '22 at 22:43