Azure自托管代理Kubernetes任务失败

huangapple go评论166阅读模式
英文:

Azure self-hosted agent kubernetes task fails

问题

我使用 Azure 自托管代理,使用 VMSS,运行代理上的 Kubernetes@1 任务时返回以下错误: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 不是私有的,当在 Azure 提供的代理上运行时,此设置是有效的。我尝试运行的任务如下:

  1. steps:
  2. - task: Kubernetes@1
  3. displayName: "Rollout <deployment-name>"
  4. inputs:
  5. connectionType: "Kubernetes Service Connection"
  6. kubernetesServiceEndpoint: <serviceEndpoint>
  7. namespace: <namespace>
  8. command: "rollout"
  9. arguments: "restart deployment <deployment-name>"

代理运行在 Ubuntu 20.04 LTS 上。

使用 AzureCLI@2 任务获取凭据并执行 kubectl 命令是可行的,但这不是最佳解决方案,我想使用 Kubernetes@1 任务。以下是可行的 AzureCLI@2 任务示例:

  1. steps:
  2. - task: AzureCLI@2
  3. inputs:
  4. azureSubscription: $(azureSubscription)
  5. scriptType: bash
  6. scriptLocation: inlineScript
  7. inlineScript: |
  8. az aks get-credentials --resource-group <resource-group> --name <aks-name>
  9. kubectl rollout -n <namespace> restart deployment <deployment-name>

编辑:

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

I am using Azure self-hosted agents using VMSS, when running Kubernetes@1 task on the agent it returns this error couldn&#39;t get current server API group list: Get &quot;https://&lt;aks&gt;.hcp.westeurope.azmk8s.io/api?timeout=32s&quot;: dial tcp: lookup &lt;aks&gt;.hcp.westeurope.azmk8s.io on 127.0.0.53:53: no such host. AKS is not private and this setup was working when running on agents provided by Azure. The task I am trying to run looks like this:

  1. steps:
  2. - task: Kubernetes@1
  3. displayName: &quot;Rollout &lt;deployment-name&gt;&quot;
  4. inputs:
  5. connectionType: &quot;Kubernetes Service Connection&quot;
  6. kubernetesServiceEndpoint: &lt;serviceEndpoint&gt;
  7. namespace: &lt;namespace&gt;
  8. command: &quot;rollout&quot;
  9. arguments: &quot;restart deployment &lt;deployment-name&gt;&quot;

Agent is running on Ubuntu 20.04 LTS.

Using AzureCLI@2 task which obtains credentials and executes kubectl command does work, but it is not optimal solution and I would like to use Kubernetes@1 task. This is example of working AzureCLI@2 task:

  1. steps:
  2. - task: AzureCLI@2
  3. inputs:
  4. azureSubscription: $(azureSubscription)
  5. scriptType: bash
  6. scriptLocation: inlineScript
  7. inlineScript: |
  8. az aks get-credentials --resource-group &lt;resource-group&gt; --name &lt;aks-name&gt;
  9. kubectl rollout -n &lt;namespace&gt; restart deployment &lt;deployment-name&gt;

EDIT:

  • I am using Service Account and not kube config file.
  • I have a custom image which comes with preinstalled kubectl command.

答案1

得分: 1

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

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

有关更多关于安装 kubectl 的信息,请参考这个链接

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

Step 3: 使用 kube config 文件创建了一个 服务连接

Step 4: 通过选择在 step 2 中创建的池运行流水线,并验证结果。

  1. - task: Kubernetes@1
  2. displayName: "Rollout nginx-deployment"
  3. inputs:
  4. connectionType: 'Kubernetes Service Connection'
  5. kubernetesServiceEndpoint: 'svc-aks'
  6. namespace: 'default'
  7. command: 'rollout'
  8. arguments: 'restart deployment nginx-deployment'
  9. secretType: 'dockerRegistry'
  10. containerRegistryType: 'Container Registry'

请注意,上述是对您提供的步骤的简要翻译。如有需要,请随时提出问题。

英文:

I have followed the steps given below and it worked for me.

Step 1: Create VMSS and install a kubectl by connecting to the VMSS.
Run the below commands on VMSS to install kubectl.

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

Azure自托管代理Kubernetes任务失败

Refer to this link for more information on installing kubectl.

Step 2: Add VMSS as self-hosted agent in ADO organization.

Azure自托管代理Kubernetes任务失败

Step 3: I have created a service connection using kube config file.

Azure自托管代理Kubernetes任务失败

Step 4: Run the pipeline by choosing the pool created in step 2 and verify the result.
Azure自托管代理Kubernetes任务失败

  1. - task: Kubernetes@1
  2. displayName: &quot;Rollout nginx-deployment&quot;
  3. inputs:
  4. connectionType: &#39;Kubernetes Service Connection&#39;
  5. kubernetesServiceEndpoint: &#39;svc-aks&#39;
  6. namespace: &#39;default&#39;
  7. command: &#39;rollout&#39;
  8. arguments: &#39;restart deployment nginx-deployment&#39;
  9. secretType: &#39;dockerRegistry&#39;
  10. containerRegistryType: &#39;Container Registry&#39;

Azure自托管代理Kubernetes任务失败

huangapple
  • 本文由 发表于 2023年3月10日 00:09:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75687209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定