kubernetes - 如何在部署yaml文件中传递参数化图像标签?

标签 kubernetes azure-pipelines devops

我的部署 yaml 文件是 bitbucket,用于构建镜像和部署容器的 CI/CD 管道位于 Azure DevOps 中。我能够正确构建和标记图像,即每次运行管道时,图像版本都会增加 1,例如1.0.0、1.0.1、1.0.2 ... 此存储库中没有“最新”标签。我如何在 deployment.yml 文件中动态传递此图像标签,以便 kubectl 部署阶段始终选择最新的标记图像?

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

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

关于kubernetes - 如何在部署yaml文件中传递参数化图像标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68750180/

相关文章:

php - 连接到同一 pod 中的 MySQL 容器

kubernetes - 在Kubernetes授权模式ABAC中使用kubectl

kubernetes - 如何通过--packages在Kubernetes托管集群中进行Spark提交?

bash - 如何导出没有元数据的 kubernetes list 文件?

azure - 创建具有受限权限的 kubeconfig

api - 无法使用 Az DevOps Pipelines API 6.0-preview.1 创建新管道

bash - Azure Devops 使用存储库名称获取 repositoryId

Azure DevOps - 自动创建管道

testing - 无法弄清楚如何在构建测试中使用 "link"按钮

azure - 无法在 Azure DevOps 中构建角度项目