[英]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 工作,它做一個碼頭構建/推送,應該比部署我的應用程序:
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)
over 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 填充匹配的注冊表/圖像並更新標簽部分
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.