使用现有设置将 AKS 中的 pods 公开到 Internet

Expose pods in AKS to internet with existing setup

我们请求将 AKS 环境中的某些 pods 公开到 Internet 以供第 3 方使用。

目前我们有一个私有 AKS 集群,前面有一个托管标准 SKU 负载均衡器,使用高级 azure 网络(基本上是 Calico),其中每个 Pod 从 Vnet IP space 获得自己的私有 IP。当前,所有私有 IP 都通过用户定义的路由通过防火墙以到达互联网,反之亦然。通过 Azure 虚拟广域网通过 VPN 连接的本地路由之间的流量。除非 100% 必要,否则我不想更改任何现有的路由行为。

我的问题是,如何公开现有私有 AKS 集群的特定 Pods 以供从 Internet 访问?整个集群不需要暴露在互联网上。我预见的问题是短暂的 Pods 和不断变化的 IP 使得防火墙中的简单 NAT 不是一个选项。我还考虑过用 public 负载均衡器简单地创建一个新的 AKS 集群。这里的问题是安全性,因为它仍然必须通过防火墙,并且可能会使用现有的用户定义路由

在 AKS 中的某些 Pods 可以通过互联网访问,同时仍然允许那些 Pods 通过私有访问 Pods 的体系结构的推荐方法是什么网络。我想避免将所有 Pods 暴露在互联网上

部署 nginx 入口控制器并将入口控制器服务绑定到 public 负载均衡器。为要从互联网访问的 kubernetes 服务定义入口规则。请注意,入口控制器启用 kubernetes

内服务 运行 的入口点

您可以使用几个选项来将您的应用程序公开给

在您的网络之外,例如:服务:

  • NodePort: Exposes the Service on each Node’s IP at a static port (the NodePort). A ClusterIP Service, to which the NodePort Service routes, is automatically created. You’ll be able to contact the NodePort Service, from outside the cluster, by requesting <NodeIP>:<NodePort>.

  • LoadBalancer: Exposes the Service externally using a cloud provider’s load balancer. NodePort and ClusterIP Services, to which the external load balancer routes, are automatically created.

此外,还有另一种选择是使用 ingress,IMO 这是向外部公开 HTTP 应用程序的最佳方式,因为可以通过以下方式创建规则路径和主机,并为您提供比服务更大的灵活性。对于入口 仅支持 HTTP/HTTPS,如果您需要 TCP,请转到服务

我建议您查看此链接以深入了解服务和入口的工作原理:

Kubernetes Services

Kubernetes Ingress

NGINX Ingress

AKS network concepts