英文:
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'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 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: "Rollout <deployment-name>"
inputs:
connectionType: "Kubernetes Service Connection"
kubernetesServiceEndpoint: <serviceEndpoint>
namespace: <namespace>
command: "rollout"
arguments: "restart deployment <deployment-name>"
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 <resource-group> --name <aks-name>
kubectl rollout -n <namespace> restart deployment <deployment-name>
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 "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
Refer to this link for more information on installing kubectl.
Step 2: Add VMSS as self-hosted agent in ADO organization.
Step 3: I have created a service connection using kube config file.
Step 4: Run the pipeline by choosing the pool created in step 2 and verify the result.
- 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'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论