如何从外部访问K8s的flannel网络

How to access K8s's flannel network from outside

我有一个 K8s 设置 1 master 和 1 minion。我想在 pods 上手动使用外部负载均衡器 (HaProxy) 对流量进行负载均衡。为此,我决定使用“Headless Service”来获取直接的 POD IP。

现在有第 3 个节点(负载均衡器)需要通过依赖网络访问 POD 或 flannel。有没有办法在 K8s 设置的法兰绒网络中加入第三个节点。或者我可以添加任何路由以将流量重定向到 flannel 网络。

P.S K8s setup(1 Master + 1 Minion) 和 3rd Node(load balancer) 在同一个子网中。

您可以查看 HAProxy 入口控制器:

HAProxy is extremely fast and resource-efficient allowing you to get the most out of your infrastructure and minimize latencies in high-traffic scenarios. It also brings an almost endless list of options for tuning and customization. HAProxy’s features like dynamic scaling and reconfiguration without reloading are also very valuable in this use case as Kubernetes pods are often spawned, terminated, and migrated in quick bursts and in high amounts, especially during deployments.

We will use the HAProxy Ingress Controller implementation available at jcmoraisjr/haproxy-ingress. It is a project to which HAProxy Technologies has contributed code that enables the Ingress Controller to take advantage of the HAProxy Runtime API. (Another useful HAProxy Ingress Controller implementation that you could look into would be appscode/voyager.)

此解决方案的主要优点是 HAProxy 入口控制器 在 Kubernetes 集群内本地运行,并且可以使用 ConfigMap 轻松配置。这意味着 HAProxy 入口控制器将使用 Flannel 覆盖网络而无需任何额外配置。

如果您决定尝试一下,本手册可能会对您有所帮助:

更新:
如果您想在集群外的实例上使用 Flannel,请考虑阅读本手册: