Azure 自托管代理 kubernetes 任务失败

标签 azure azure-devops azure-pipelines azure-pipelines-tasks

运行 Kubernetes@1 时,我正在使用使用 VMSS 的 Azure 自托管代理代理上的任务会返回此错误 couldn't get current server API group list: Get "https://<aks>.hcp.westeurope.azmk8s.io/api?timeout=32s": dial tcp: lookup <aks>.hcp.westeurope.azmk8s.io on 127.0.0.53:53: no such host 。 AKS 不是私有(private)的,并且此设置在 Azure 提供的代理上运行时有效。我尝试运行的任务如下所示:

steps:
  - task: Kubernetes@1
    displayName: "Rollout <deployment-name>"
    inputs:
      connectionType: "Kubernetes Service Connection"
      kubernetesServiceEndpoint: <serviceEndpoint>
      namespace: <namespace>
      command: "rollout"
      arguments: "restart deployment <deployment-name>"

代理正在 Ubuntu 20.04 LTS 上运行。

使用AzureCLI@2获取凭据并执行 kubectl 的任务命令确实有效,但它不是最佳解决方案,我想使用 Kubernetes@1任务。这是工作示例AzureCLI@2任务:

steps:
 - task: AzureCLI@2
    inputs:
      azureSubscription: $(azureSubscription)
      scriptType: bash
      scriptLocation: inlineScript
      inlineScript: |
        az aks get-credentials --resource-group <resource-group> --name <aks-name>
        kubectl rollout -n <namespace> restart deployment <deployment-name>

编辑:

  • 我使用的是服务帐户,而不是 kube 配置文件。
  • 我有一个自定义镜像,附带预安装的 kubectl 命令。

最佳答案

我已按照以下步骤操作,它对我有用。

第 1 步:创建 VMSS 并通过连接到 VMSS 安装 kubectl。 在 VMSS 上运行以下命令来安装 kubectl。

$curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
$sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

enter image description here

引用这个link有关安装 kubectl 的更多信息。

步骤 2:将 VMSS 添加为 ADO 组织中的自托管代理。

enter image description here

第 3 步:我已使用 kube config 文件创建了服务连接

enter image description here

第 4 步:通过选择在第 2 步中创建的池来运行管道并验证结果。 enter image description here

  - task: Kubernetes@1
    displayName: "Rollout nginx-deployment"
    inputs:
      connectionType: 'Kubernetes Service Connection'
      kubernetesServiceEndpoint: 'svc-aks'
      namespace: 'default'
      command: 'rollout'
      arguments: 'restart deployment nginx-deployment'
      secretType: 'dockerRegistry'
      containerRegistryType: 'Container Registry'

enter image description here

关于Azure 自托管代理 kubernetes 任务失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75687209/

相关文章:

azure - 如何在 Azure 专用 SQL 池/Azure Synapse 中查找物化 View 的大小(以 MB/GB 为单位)

azure-pipelines - Id : . ...的任务定义的任务执行部分丢失或无效

azure-devops - Azure DevOps YAML 管道参数不适用于 REST API 触发器

Azure DevOps 构建 yaml : "No repository found by name templates" even though it is displayed

azure - 从所有表的 azure databricks 数据库列获取值

Azure Web服务每隔几个小时更新一次相同的docker镜像

Azure 认知服务 - TTS

azure-devops - 无法将用户添加到 Azure DevOps 项目

powershell - 如何在 DevOps 管道中将 yml 对象传递给 powershell?

Azure Pipeline Matrix策略变量扩展问题与模板结合使用