簡體   English   中英

如何在部署 yaml 文件中傳遞參數化圖像標簽?

[英]How to pass parametrized image tag in the deployment yaml file?

我的部署 yaml 文件是 bitbucket 和 CI/CD 管道來構建圖像和部署容器在 Azure DevOps 中。 我能夠正確地構建和標記圖像,即在每個管道運行時,圖像版本都會增加 1,例如 1.0.0、1.0.1、1.0.2... 這個存儲庫中沒有“最新”標簽。 如何在 deployment.yml 文件中動態傳遞此圖像標記,以便 kubectl deploy 階段始終選擇最新的標記圖像?

我的部署文件目前看起來像:

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

我試圖將圖像更改為 - image: acr/ubuntu-custom 但出現 ImagePullBackOff 錯誤。

我確定我需要在部署文件中傳遞最新的標簽,但我不確定如何實現這一點。

  1. 使用 sed 命令

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

  2. 使用 yq

    yq -i -y ".spec. template.spec.containers.image = \\"${ACR_REPO_URL}\\"" 
 deploy.yaml

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM