简体   繁体   English

何时在 K8s 中使用外部 LoadBalancer?

[英]When to use external LoadBalancer in K8s?

Explaining my confusion / lack of understanding解释我的困惑/缺乏理解

When reading about the external LoadBalancer in K8s , which is a cloud provider only feature, I don't quite understand when it should be used, as when one creates a Deployment K8s will do Round Robin load balancing on the pods in that Deployment.当阅读K8s 中的外部 LoadBalancer 时,这是一个云提供商独有的功能,我不太明白什么时候应该使用它,因为当创建一个部署时,K8s 将在该部署中的 Pod 上进行循环负载平衡。

So from my current understanding all one would need to do is make a NodeIP, and you have the equivalent of an external load balancer?因此,根据我目前的理解,所有需要做的就是制作一个 NodeIP,并且您拥有相当于外部负载均衡器的功能?

Or should I think of the LoadBalancer type as haproxy/nginx/Envoy, where one can do SSL, reverse proxy, and many other useful things?或者我应该将 LoadBalancer 类型视为 haproxy/nginx/Envoy,在那里可以做 SSL、反向代理和许多其他有用的事情?

My current guess is that the proper use of LoadBalancer is to add many NodeIP's, but I can't find anything to back that up.我目前的猜测是 LoadBalancer 的正确使用是添加许多 NodeIP,但我找不到任何支持它的东西。

Question问题

Can anyone explain when and why to use LoadBalancer and not just using the NodeIP?谁能解释何时以及为什么使用 LoadBalancer 而不仅仅是使用 NodeIP?

For example, You want to deploy multiple applications in your cluster, say 10 apps.例如,您想在集群中部署多个应用程序,例如 10 个应用程序。 You would like to access these 10 apps over internet.您想通过互联网访问这 10 个应用程序。 One way is to set those 10 application services as nodeport so you can access them from outside.一种方法是将这 10 个应用程序服务设置为节点端口,以便您可以从外部访问它们。 For this to happen kubernetes opens 10 nodeports on each cluster node.为此,kubernetes 在每个集群节点上打开 10 个节点端口。 This is a security risk.这是一个安全风险。

In most of the enterprises where they work behind firewall in a closed network dont allow external traffic to/from any ports other than http/https ( 80/443 ).在大多数企业中,他们在封闭网络中的防火墙后面工作,不允许外部流量进出 http/https (80/443) 以外的任何端口。

One way is to set service type as Loadbalancer for each application service.一种方法是将服务类型设置为每个应用程序服务的负载均衡器。 So, to access 10 app, you will be provisioning 10 load balancers to access the app servers over http/https ports.因此,要访问 10 个应用程序,您将配置 10 个负载均衡器以通过 http/https 端口访问应用程序服务器。 Since loadbalancers are charged resources, economically it is not viable to have one load balancer for each service that you want to access over itnernet.由于负载均衡器是对资源收费的,因此从经济上讲,为要通过 itnernet 访问的每项服务使用一个负载均衡器是不可行的。

Is there a way to access all those 10 app services running inside kubernetes over single port.有没有办法通过单端口访问在 kubernetes 中运行的所有这 10 个应用程序服务。 This is where ingress controller comes into picture.这就是入口 controller 出现的地方。

Ingress controller allows single ip-port to access all services running in k8s through ingress rules. Ingress controller 允许单个 ip-port 通过 ingress 规则访问在 k8s 中运行的所有服务。 The ingress controller service is set to load balancer so it is accessible from public internet入口 controller 服务设置为负载均衡器,因此可以从公共互联网访问

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM