Azure kubernetes:将驻留在另一个子网中的 VM 连接到容器

Azure kubernates : connect VM residing in another subnet to container

所以我在子网 A 的 Azure Kubernetes 集群中部署了一个包含微服务的容器。我还有另一个微服务 运行 在虚拟机上但在另一个子网 B 中。我必须调用 rest APIs来自 VM 的容器内的应用程序 运行。我怎样才能实现它?

实现该目标的正确方法是创建 internal load balancer.

来自文档:

To restrict access to your applications in Azure Kubernetes Service (AKS), you can create and use an internal load balancer. An internal load balancer makes a Kubernetes service accessible only to applications running in the same virtual network as the Kubernetes cluster.

关注 Specify a different subnet 部分:

To specify a subnet for your load balancer, add the azure-load-balancer-internal-subnet annotation to your service. The subnet specified must be in the same virtual network as your AKS cluster. When deployed, the load balancer EXTERNAL-IP address is part of the specified subnet.

示例:

apiVersion: v1
kind: Service
metadata:
  name: internal-app
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-internal: "true"
    service.beta.kubernetes.io/azure-load-balancer-internal-subnet: "apps-subnet"
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: internal-app

图: