从 Azure 容器注册表部署 Helm Chart

问题描述 投票:0回答:4

我有一个具有以下内容的多级管道

舞台搭建:

  1. 构建docker镜像
  2. 将图像推送至 ACR
  3. 包舵图
  4. 将舵图表推至 ACR

舞台部署:

  1. 头盔升级

将舵图推送到 AKS:

 task: HelmDeploy@0
 displayName: 'helm publish'
 inputs:
   azureSubscriptionForACR: '$(azureSubscription)'
   azureResourceGroupForACR: '$(resourceGroup)'
   azureContainerRegistry: '$(containerRegistry)'
   command: 'save'
   arguments: '--app-version $(Version)'
   chartNameForACR: 'charts/$(imageRepository):$(Version)'
   chartPathForACR: $(chartPath)

将 Helm Chart 部署到 AKS:

  task: HelmDeploy@0
  inputs:
    connectionType: 'Kubernetes Service Connection'
    kubernetesServiceConnection: '$(kubernetesServiceConnection)'
    command: 'upgrade'
    chartType: 'Name'
    chartName: '$(containerRegistry)/charts/$(imageRepository):$(Version)'
    chartVersion: '$(Version)'
    azureSubscriptionForACR: '$(azureSubscription)'
    azureResourceGroupForACR: '$(resourceGroup)'
    azureContainerRegistry: '$(containerRegistry)'
    install: true
    releaseName: $(Version)

错误:

failed to download "<ACR>/charts/<repository>:0.9.26" at version "0.9.26" (hint: running `helm repo update` may help)

ACR:

az acr repository show-manifests --name <org> --repository helm/charts/<repository> --detail

  {
    "changeableAttributes": {
      "deleteEnabled": true,
      "listEnabled": true,
      "readEnabled": true,
      "writeEnabled": true
    },
    "configMediaType": "application/vnd.cncf.helm.config.v1+json",
    "createdTime": "2021-02-02T11:54:54.1623765Z",
    "digest": "sha256:fe7924415c4e76df370630bbb0248c9296f27186742e9272eeb87b2322095c83",
    "imageSize": 3296,
    "lastUpdateTime": "2021-02-02T11:54:54.1623765Z",
    "mediaType": "application/vnd.oci.image.manifest.v1+json",
    "tags": [
      "0.9.26"
    ]
  }

我做错了什么?我是否必须先

export
ACR 中的 helm 图表才能部署它?

kubernetes azure-pipelines kubernetes-helm acr
4个回答
3
投票

@sshepel 的答案实际上有所帮助,您需要登录注册表才能拉取。不过,只需简单的 AzureCLI 登录就足够了。

    - task: AzureCLI@2
      displayName: Login to Azure Container Registry
      inputs:
        azureSubscription: <Azure Resource Manager service connection to your subscription and resource group>
        scriptType: bash
        scriptLocation: inlineScript
        inlineScript: |
          az acr login --name <container registry name>.azurecr.io

此后,它与未记录的 HelmDeploy 任务完美配合。


0
投票

我遇到了同样的问题,唯一对我有帮助的选择是在 helm 升级之前添加注册表登录步骤。

- task: Bash@3
  name: registryLogin
  displayName: Login registry
  env:
   SERVICE_PRINCIPAL_APPLICATION_ID: <SPN_APP_ID>
   SERVICE_PRINCIPAL_APPLICATION_KEY: <SPN_APP_KEY>
   HELM_EXPERIMENTAL_OCI: 1 # just in case...
  input:
   targetType: inline
   script:
     echo $SERVICE_PRINCIPAL_APPLICATION_KEY | helm registry login <acr_name>.azurecr.io --username $SERVICE_PRINCIPAL_APPLICATION_ID --password-stdin

0
投票

我从来没有找到解决这个问题的方法,所以我最终找到了另一个解决方案。

我没有尝试将包发布到注册表,而是将其作为工件发布到管道。 在部署步骤中,我下载了工件并将其应用到kubernetes。

这样做的好处是可以轻松回滚到特定版本,只需在所需管道中重新运行特定部署阶段即可。

Sudo 管道:

Stage: build
  build
  test
  generate image
  publish image to registry
  generate helm package (setting helm version and image tag)
  publish package as azure artifacts
Stage: Test deployment
  download artifacts
  apply helm package
Stage: Prod deployment
  download artifacts
  apply helm package

-1
投票

helm upgrade
的语法应该是这样的:

- task: HelmDeploy@0
  displayName: 'helm upgrade'
  inputs:
    connectionType: 'Kubernetes Service Connection'
    kubernetesServiceConnection: connection
    command: upgrade
    chartName: '$(name)'
    chartVersion: '$(Version)'
    releaseName: azuredevopsdemo

尝试将

chartName
值替换为
charts/$(imageRepository)

© www.soinside.com 2019 - 2024. All rights reserved.