3

My deployment yaml file is bitbucket and CI/CD pipeline to build the image and deploy the container is in Azure DevOps. I am able to build and tag the image correctly i.e. with each pipeline run the image version is incremented by 1 e.g. 1.0.0, 1.0.1,1.0.2 ... There is no "latest" tag in this repository. How do I pass this image tag dynamically in the deployment.yml file so that kubectl deploy stage always picks the latest tagged image ?

my deployment file currently looks like:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ubuntu-custom
  labels:
    app: ubuntu-custom
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ubuntu-custom
  template:
    metadata:
      labels:
        app: ubuntu-custom
    spec:
      containers:
      - name: ubuntu-custom
        image:  <acr>/ubuntu-custom:latest
        command: ["sleep"]
        args: ["365d"]
      imagePullSecrets:
      - name: acrsecret

I have tried to change the image to - image: acr/ubuntu-custom but I get the ImagePullBackOff error.

I am sure I need to pass the latest tag in the deployment file but I am not sure how I can achieve that.

David Maze
  • 130,717
  • 29
  • 175
  • 215
notageek27
  • 101
  • 1
  • 6
  • Generally, you would want some sort of CI/CD system doing that, i.e. this is how we do it: https://itnext.io/building-kubernetes-cicd-pipeline-with-github-actions-argocd-and-reliza-hub-e7120b9be870 – taleodor Aug 12 '21 at 02:58

1 Answers1

1
  1. Use sed command

    sed 's/\\<arc\\>/${ACR_REPO_URL}/g' deploy.yaml

  2. Use yq

    yq -i -y ".spec. template.spec.containers.image = \\"${ACR_REPO_URL}\\"" 
 deploy.yaml
T.R
  • 126
  • 7