【发布时间】:2021-03-20 15:56:48
【问题描述】:
我正在学习 K8s,并使用 kubectl apply 设置了发布管道。我已经通过 Terraform 设置了 AKS 集群,在第一次运行时一切似乎都很好。一旦我破坏了集群,我重新运行了管道,我得到了我认为与异常中提到的 kubeconfig 文件有关的问题。我尝试了 cloud shell 等来获取文件或重置它,但我没有成功。我怎样才能回到干净的状态?
2020-12-09T09:08:51.7047177Z ##[section]Starting: kubectl apply
2020-12-09T09:08:51.7482440Z ==============================================================================
2020-12-09T09:08:51.7483217Z Task : Kubectl
2020-12-09T09:08:51.7483729Z Description : Deploy, configure, update a Kubernetes cluster in Azure Container Service by running kubectl commands
2020-12-09T09:08:51.7484058Z Version : 0.177.0
2020-12-09T09:08:51.7484996Z Author : Microsoft Corporation
2020-12-09T09:08:51.7485587Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/kubernetes
2020-12-09T09:08:51.7485955Z ==============================================================================
2020-12-09T09:08:52.7640528Z [command]C:\ProgramData\Chocolatey\bin\kubectl.exe --kubeconfig D:\a\_temp\kubectlTask\1607504932712\config apply -f D:\a\r1\a/medquality-cordapp/k8s
2020-12-09T09:08:54.1555570Z Unable to connect to the server: dial tcp: lookup mq-k8s-dfee38f6.hcp.switzerlandnorth.azmk8s.io: no such host
2020-12-09T09:08:54.1798118Z ##[error]The process 'C:\ProgramData\Chocolatey\bin\kubectl.exe' failed with exit code 1
2020-12-09T09:08:54.1853710Z ##[section]Finishing: kubectl apply
发布管道的更新、工作流任务:
最初我得到了工件,克隆了包含 k8s yamls 的 repo,然后这个阶段应用了 kubectl。
"workflowTasks": [
{
"environment": {},
"taskId": "cbc316a2-586f-4def-be79-488a1f503564",
"version": "0.*",
"name": "kubectl apply",
"refName": "",
"enabled": true,
"alwaysRun": false,
"continueOnError": false,
"timeoutInMinutes": 0,
"definitionType": null,
"overrideInputs": {},
"condition": "succeeded()",
"inputs": {
"kubernetesServiceEndpoint": "82e5971b-9ac6-42c6-ac43-211d2f6b60e4",
"namespace": "",
"command": "apply",
"useConfigurationFile": "false",
"configuration": "",
"arguments": "-f $(System.DefaultWorkingDirectory)/medquality-cordapp/k8s",
"secretType": "dockerRegistry",
"secretArguments": "",
"containerRegistryType": "Azure Container Registry",
"dockerRegistryEndpoint": "",
"azureSubscriptionEndpoint": "",
"azureContainerRegistry": "",
"secretName": "",
"forceUpdate": "true",
"configMapName": "",
"forceUpdateConfigMap": "false",
"useConfigMapFile": "false",
"configMapFile": "",
"configMapArguments": "",
"versionOrLocation": "version",
"versionSpec": "1.7.0",
"checkLatest": "false",
"specifyLocation": "",
"cwd": "$(System.DefaultWorkingDirectory)",
"outputFormat": "json",
"kubectlOutput": ""
}
}
]
```
【问题讨论】:
-
您能否分享管道步骤并提供更多详细信息。您是否在管道本身中为新创建的集群获取 kubeconfig?
-
我已经更新了 OP,我没有获取 kubeconfig。
-
Kubectl 将需要信息来连接到您的新集群。您将需要获取集群信息并使用集群的详细信息更新您的 kubeconfig 文件。其中一种方法是,您可以在管道中调用 kubectl apply 之前使用 Az CLI 任务 (az aks get-credentials) 更新 kubeconfig。
-
我在 kubectl apply 任务之前使用了 Radek 在任务中给出的命令,但同样的问题。一定还是做错了什么。
2020-12-09T13:09:44.8926956Z Merged "medquality-aks1-admin" as current context in /home/vsts/.kube/config 2020-12-09T13:09:45.2265525Z [command]/usr/bin/az account clear -
您是否仍然收到“无法连接到服务器:拨号 tcp:查找 mq-k8s-dfee38f6.hcp.switzerlandnorth.azmk8s.io”?如果是新的错误信息,可以在这里添加吗?
标签: azure kubernetes azure-devops terraform-provider-azure