Azure Pipeline 部署到 Kubernetes:覆盖图像参考
Azure Pipline Deploy to Kubernetes: Override image reference
我有一个包含一个容器的 deployment.yml 文件,如下所示:
apiVersion: apps/v1
kind: Deployment
[...]
spec:
containers:
- name: my-app
image: acr/my-app:1.0 #-> should be completly overridden!
和一个 Azure DevOps 作业,它做一个停靠 build/push 并且应该部署我的应用程序:
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
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.
您需要确保清单中的字符串与 KubernetesManifestTask
中的 registry/image:tag 字符串匹配
Azure DevOps 填充 wine 匹配 registry/image 并更新标签部分
我有一个包含一个容器的 deployment.yml 文件,如下所示:
apiVersion: apps/v1
kind: Deployment
[...]
spec:
containers:
- name: my-app
image: acr/my-app:1.0 #-> should be completly overridden!
和一个 Azure DevOps 作业,它做一个停靠 build/push 并且应该部署我的应用程序:
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
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.
您需要确保清单中的字符串与 KubernetesManifestTask
中的 registry/image:tag 字符串匹配Azure DevOps 填充 wine 匹配 registry/image 并更新标签部分