Azure Pipline部署到Kubernetes:覆盖映像引用

Azure Pipline部署到Kubernetes:覆盖映像引用,azure,kubernetes,azure-devops,azure-aks,Azure,Kubernetes,Azure Devops,Azure Aks,我有一个带有一个容器的deployment.yml文件,如下所示: apiVersion: apps/v1 kind: Deployment [...] spec: containers: - name: my-app image: acr/my-app:1.0 #-> should be completly overridden! 以及一个Azure DevOps作业,该作业执行dock构建/推送,并且应该部署我的应用程序: va

我有一个带有一个容器的deployment.yml文件,如下所示:

apiVersion: apps/v1
kind: Deployment
[...]
    spec:
      containers:
        - name: my-app
          image: acr/my-app:1.0 #-> should be completly overridden!
以及一个Azure DevOps作业,该作业执行dock构建/推送,并且应该部署我的应用程序:

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)
我希望覆盖deployment.yml中的完整映像引用值。但我不知道如何写一个有效的占位符。我尝试了很多不同的东西,从
$(VALUE)
VALUE
到`{{VALUE}},例如:

image:${{variables.containerRegistry}/${{variables.imageRepository}:${{variables.tag}}
。但是占位符根本没有被替换,pod失败,图像引用无效

Azure DevOps可以这样做吗?或者我需要通过bash任务或类似的方式覆盖映像值吗

更新

为了澄清我的要求: 我想重写完整的字符串,因为我想在多个阶段重用文件,在这些阶段中,只有注册表和标记是困难的。例如:
acr1/my-app:tag1
acr2/my-app:tag2

取自

您需要确保清单中的字符串与KubernetesManifestTask中的registry/image:tag字符串匹配


Azure DevOps填充匹配的注册表/图像并更新标记部分

谢谢,我已经尝试过了,但它只在yml中有
image:registry/image:tag
的情况下有效。但是我想覆盖整个字符串,因为我想在多个阶段重用文件,其中只有注册表和标记是困难的。例如:
acr1/my-app:tag1
acr2/my-app:tag2
在这种情况下,您需要使用kustomize或helm2烘焙您的清单,并使用烘焙操作,这将允许您在将清单传递给KubernetesManifest任务之前对清单进行模板化并更改图像。好的,我希望可以绕过这一额外步骤。无论如何谢谢你!
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.