在 azure devops 部署期间覆盖 helm chart 中的配置映射

override config map in helm chart during azure devops deploy

我们正在使用 Helm 图表模板部署到 CI/CD 的 kube 和 Azure devops。在我的 values.yaml data 下面的部分将根据环境并保存为 pod 中的配置映射。 我的问题是如何在 Azure 管道部署期间更新它。我们正在使用 Helm 升级任务或任何其他方式来更好地处理它。

environment:
    enabled: true
    env:
      enabled: false
    internalConfigMap:
      enabled: true
      **data:
        AZ_DIRECTORY: xxx
        MODEL_ID_SVM: xxx
        MODEL_ID_MULTI: xxx
        MODEL_THRESHOLD_SVM: 'xx'
        SINGLE_ACC_ENDPT: 'xx'
        MODEL_WT_SVM: 'xx'**

这里是部署任务:(忽略缩进)

task: HelmDeploy@0
     displayName: Helm upgrade
                inputs:
                  command: upgrade
                  chartType: Name
                  chartName: chart/$(chartname)
                  releaseName: $(chartname)-${{ parameters.CI_ENVIRONMENT_SLUG }}
                  namespace: $(NAMESPACE)
                  connectionType: Azure Resource Manager
                  #azureSubscriptionEndpoint: ${{ variables.AZ_SUBSCRIPTION }}
                  #azureResourceGroup: $(AKS_RESOURCE_GROUP)
                # kubernetesCluster: $(K8S_CLUSTER)
                  install: true
                  waitForExecution: true
                  useClusterAdmin: true
                  overrideValues: |
                    template.image.tag=$(imagetag)

选项 1:每个环境一个值文件

如果每个环境(environment1-values.yamlenvironment2-values.yaml 等)有一个 values.yaml,您可以为管道中的每个阶段引用不同的文件。

The Helm Upgrade command 接受参数 valueFile,您可以使用该参数为要部署到的环境指向正确的 values.yaml

(Optional) Specify values in a YAML file or a URL. For example, specifying myvalues.yaml will result in helm install --values=myvals.yaml

选项 2:覆盖部署时的值

The Helm Upgrade command 接受参数 overrideValues,您可以通过它直接将值传递给 helm:

(Optional) Set values on the command line. You can specify multiple values by separating values with commas. For example, key1=val1,key2=val2. You can also specify multiple values by delimiting them with newline as so: key1=val1 key2=val2 Please note that if you have a value which itself contains newlines, use the valueFile option, else the task will treat the newline as a delimiter. The task will construct the helm command by using these set values. For example, helm install --set key1=val1 ./redis

在你的情况下,这意味着

   overrideValues: template.image.tag=$(imagetag),environment.internalConfigMap.data.AZ_DIRECTORY=xxx,environment.internalConfigMap.data.MODEL_ID_SVM=xxx