Azure自托管代理Kubernetes任务失败

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

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 提供的代理上运行时,此设置是有效的。我尝试运行的任务如下:

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 命令的自定义映像。
英文:

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:

steps:
  - task: Kubernetes@1
    displayName: &quot;Rollout &lt;deployment-name&gt;&quot;
    inputs:
      connectionType: &quot;Kubernetes Service Connection&quot;
      kubernetesServiceEndpoint: &lt;serviceEndpoint&gt;
      namespace: &lt;namespace&gt;
      command: &quot;rollout&quot;
      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:

steps:
 - task: AzureCLI@2
    inputs:
      azureSubscription: $(azureSubscription)
      scriptType: bash
      scriptLocation: inlineScript
      inlineScript: |
        az aks get-credentials --resource-group &lt;resource-group&gt; --name &lt;aks-name&gt;
        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。

$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

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

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

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

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

  - 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'

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

英文:

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.

$curl -LO &quot;https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl&quot;
$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任务失败

  - task: Kubernetes@1
    displayName: &quot;Rollout nginx-deployment&quot;
    inputs:
      connectionType: &#39;Kubernetes Service Connection&#39;
      kubernetesServiceEndpoint: &#39;svc-aks&#39;
      namespace: &#39;default&#39;
      command: &#39;rollout&#39;
      arguments: &#39;restart deployment nginx-deployment&#39;
      secretType: &#39;dockerRegistry&#39;
      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:

确定