Azure DevOps 使用自托管代理:无法部署到 AKS 集群

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

azure devops with self Hosted agent : can't deploy to aks cluster

问题

我想创建一个Azure DevOps发布管道,用于构建Docker镜像并将其部署到AKS集群。

构建和部署到ACR工作正常,但是部署到AKS不起作用。

这是运行管道后的结果:

Azure DevOps 使用自托管代理:无法部署到 AKS 集群

这是错误日志:

2023-01-08T22:20:48.7666031Z ##[section]Starting: deploy
2023-01-08T22:20:48.7737773Z ==============================================================================
2023-01-08T22:20:48.7741356Z Task         : 部署到 Kubernetes
2023-01-08T22:20:48.7745738Z Description  : 使用Kubernetes清单文件部署到集群,甚至可以使用Helm图表来生成用于部署的清单文件
2023-01-08T22:20:48.7750005Z Version      : 0.212.0
2023-01-08T22:20:48.7752721Z Author       : 微软公司
2023-01-08T22:20:48.7755489Z Help         : https://aka.ms/azpipes-k8s-manifest-tsg
2023-01-08T22:20:48.7757618Z ==============================================================================
2023-01-08T22:20:49.2976400Z Downloading: https://storage.googleapis.com/kubernetes-release/release/stable.txt
2023-01-08T22:20:49.8627101Z Found tool in cache: kubectl 1.26.0 x64
2023-01-08T22:20:50.6940515Z ==============================================================================
2023-01-08T22:20:50.6942077Z 			Kubectl客户端版本:v1.26.0
2023-01-08T22:20:50.6943172Z 			Kubectl服务器版本:v1.23.12
2023-01-08T22:20:50.6944430Z ==============================================================================
2023-01-08T22:20:50.7161602Z [command]/azp/_work/_tool/kubectl/1.26.0/x64/kubectl apply -f /azp/_work/_temp/Deployment_acrdemo2ss-deployment_1673216450713,/azp/_work/_temp/Service_acrdemo2ss-loadbalancer-service_1673216450713 --namespace dev
2023-01-08T22:20:50.9679948Z 无法连接到服务器:拨号tcp:在192.168.1.1:53上查找tfkcluster-dns-074e9373.hcp.canadacentral.azmk8s.io:没有这样的主机
2023-01-08T22:20:50.9771688Z ##[error]无法连接到服务器:拨号tcp:在192.168.1.1:53上查找tfkcluster-dns-074e9373.hcp.canadacentral.azmk8s.io:没有这样的主机
2023-01-08T22:20:50.9809463Z ##[section]Finishing: deploy

这是我的服务连接:

Azure DevOps 使用自托管代理:无法部署到 AKS 集群

英文:

i want to create azure devops release pipeline that build a docker image and deploy it to aks cluster .

the build and deployment to acr work well but the deployment to aks doesn't work.

this is the results after runing the pipeline :

Azure DevOps 使用自托管代理:无法部署到 AKS 集群

and this is the error logs :

2023-01-08T22:20:48.7666031Z ##[section]Starting: deploy
2023-01-08T22:20:48.7737773Z ==============================================================================
2023-01-08T22:20:48.7741356Z Task         : Deploy to Kubernetes
2023-01-08T22:20:48.7745738Z Description  : Use Kubernetes manifest files to deploy to clusters or even bake the manifest files to be used for deployments using Helm charts
2023-01-08T22:20:48.7750005Z Version      : 0.212.0
2023-01-08T22:20:48.7752721Z Author       : Microsoft Corporation
2023-01-08T22:20:48.7755489Z Help         : https://aka.ms/azpipes-k8s-manifest-tsg
2023-01-08T22:20:48.7757618Z ==============================================================================
2023-01-08T22:20:49.2976400Z Downloading: https://storage.googleapis.com/kubernetes-release/release/stable.txt
2023-01-08T22:20:49.8627101Z Found tool in cache: kubectl 1.26.0 x64
2023-01-08T22:20:50.6940515Z ==============================================================================
2023-01-08T22:20:50.6942077Z 			Kubectl Client Version: v1.26.0
2023-01-08T22:20:50.6943172Z 			Kubectl Server Version: v1.23.12
2023-01-08T22:20:50.6944430Z ==============================================================================
2023-01-08T22:20:50.7161602Z [command]/azp/_work/_tool/kubectl/1.26.0/x64/kubectl apply -f /azp/_work/_temp/Deployment_acrdemo2ss-deployment_1673216450713,/azp/_work/_temp/Service_acrdemo2ss-loadbalancer-service_1673216450713 --namespace dev
2023-01-08T22:20:50.9679948Z Unable to connect to the server: dial tcp: lookup tfkcluster-dns-074e9373.hcp.canadacentral.azmk8s.io on 192.168.1.1:53: no such host
2023-01-08T22:20:50.9771688Z ##[error]Unable to connect to the server: dial tcp: lookup tfkcluster-dns-074e9373.hcp.canadacentral.azmk8s.io on 192.168.1.1:53: no such host
2023-01-08T22:20:50.9809463Z ##[section]Finishing: deploy

this is my service connection :

Azure DevOps 使用自托管代理:无法部署到 AKS 集群

答案1

得分: 0

无法连接到服务器:在192.168.1.1:53上拨号tcp:查找xxxx:没有这样的主机

看起来您正在使用私有集群(在创建AKS集群时启用了私有集群选项)。

Kubectl是Kubernetes控制客户端。它是与Kubernetes集群连接的外部连接提供程序。我们无法从外部连接到私有集群。

然而,在集群创建后,我们无法禁用此选项。我们需要删除该集群,并创建一个新的,选项为“Private Cluster”禁用。

或者,您可以设置另一个自托管代理,它将与集群位于同一虚拟网络中,并具有访问AKS和Azure管道的权限。

请参阅连接到私有集群的选项

API服务器端点没有公共IP地址。要管理API服务器,您需要使用具有访问AKS集群Azure虚拟网络(VNet)的VM。有几种建立与私有集群的网络连接的选项。

  • 在与AKS集群相同的Azure虚拟网络(VNet)中创建VM。
  • 使用位于不同网络中的VM并设置虚拟网络互联。有关此选项的更多信息,请参阅下面的部分。
  • 使用Express Route或VPN连接。
  • 使用AKS命令调用功能。
  • 使用私有端点连接。

在与AKS集群相同的VNET中创建VM是最简单的选项。Express Route和VPN会增加成本并需要额外的网络复杂性。虚拟网络互连要求您计划您的网络CIDR范围,以确保没有重叠的范围。

英文:

> Unable to connect to the server: dial tcp: lookup xxxx on
> 192.168.1.1:53: no such host

It appears that you are using a private cluster (The Private Cluster option is enabled while creating the AKS cluster).

Azure DevOps 使用自托管代理:无法部署到 AKS 集群

Kubectl is a kubernetes control client. It is an external connectivity provider to connect with kubernetes cluster. We can't connect with the private cluster externally.

However, we can't disable this option after the cluster creation. We need to delete the cluster and create a new one with the option "Private Cluster" disabled.

Alternately, you can set up another self-hosted agent which will be in the same Vnet as the cluster and have access to AKS and the Azure Pipelines.

See Options for connecting to the private cluster

> The API server endpoint has no public IP address. To manage the API
> server, you'll need to use a VM that has access to the AKS cluster's
> Azure Virtual Network (VNet). There are several options for
> establishing network connectivity to the private cluster.
>
> - Create a VM in the same Azure Virtual Network (VNet) as the AKS cluster.
> - Use a VM in a separate network and set up Virtual network peering. See the section below for more information on this option.
> - Use an Express Route or VPN connection.
> - Use the AKS command invoke feature.
> - Use a private endpoint connection.
>
> Creating a VM in the same VNET as the AKS cluster is the easiest
> option. Express Route and VPNs add costs and require additional
> networking complexity. Virtual network peering requires you to plan
> your network CIDR ranges to ensure there are no overlapping ranges.

huangapple
  • 本文由 发表于 2023年1月9日 06:31:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75051731.html
匿名

发表评论

匿名网友

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

确定