简体   繁体   中英

Azure Pipline Deploy to Kubernetes: Override image reference

I have an deployment.yml file with one container, something like this:

apiVersion: apps/v1
kind: Deployment
[...]
    spec:
      containers:
        - name: my-app
          image: acr/my-app:1.0 #-> should be completly overridden!

and an Azure DevOps job that does a dock build/push and should than deploy my app:

variables:
  imageRepository: 'my-app'
  containerRegistry: 'acr'
  dockerfilePath: '$(Build.SourcesDirectory)/myapp/Dockerfile'
  tag: '$(Build.BuildId)'

[...]

- task: KubernetesManifest@0
      displayName: Deploy on kubernetes cluster
      inputs:
        action: 'deploy'
        kubernetesServiceConnection: '...'
        namespace: 'default'
        manifests: '$(Build.SourcesDirectory)/deployment.yml'
        containers: |
          $(containerRegistry)/$(imageRepository):$(tag)

I want the complete image reference value in the deployment.yml to be overridden. But I don't get how to write a working placeholder. I tried many different things, from $(VALUE) over VALUE to ``{{ VALUE }},eg:

image: ${{ variables.containerRegistry }} / ${{ variables.imageRepository }}: ${{ variables.tag}} . But the placeholder is not replaced at all and the pod fails with invalid image refernece.

Can Azure DevOps do this or do I need to override the image value via bash task or something like this?

Update

To clarify my requirements: I want to override the complete string, since I want to reuse the file for multiple stages, where only the registry the tag are difficult. Eg: acr1/my-app:tag1 and acr2/my-app:tag2

taken from https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/kubernetes-manifest?view=azure-devops

The fully qualified URL of the image to be used for substitutions on the manifest files. This input accepts the specification of multiple artifact substitutions in newline-separated form. Here's an example:

containers: |
  contosodemo.azurecr.io/foo:test1
  contosodemo.azurecr.io/bar:test2

In this example, all references to contosodemo.azurecr.io/foo and contosodemo.azurecr.io/bar are searched for in the image field of the input manifest files. For each match found, the tag test1 or test2 replaces the matched reference.

You will need to ensure that the string in your manifest matches the registry/image:tag string in your KubernetesManifestTask

Azure DevOps fill wine the matching registry/image and update the tag portion

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM