将Nginx暴露为负载平衡器与Ingress控制器有什么区别? [英] What's the difference between exposing nginx as load balancer vs Ingress controller?

查看:76
本文介绍了将Nginx暴露为负载平衡器与Ingress控制器有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解,当我们想通过单个负载均衡器/公共IP公开多个服务/路由时,可以使用Ingress.

I understood Ingress can be used when we want to expose multiple service/routes with a single Load Balancer / public IP.

现在,我想将我的Nginx服务器公开.我有两个选择

Now I want to expose my Nginx server to public. I have two choices

  1. 设置service type as LoadBalancer瞧,我获得了公共IP
  2. 使用 Nginx入口控制器
  1. Set service type as LoadBalancer voila I got public IP
  2. Use Nginx Ingress Controller

现在我何时可以选择选项1来完成我的工作,为什么选择选项2呢?为什么在没有Ingress的情况下使用具有Ingress的nginx有什么好处?

Now I can get my job done with Option 1 when or why would I choose Option 2 whats the advantage of having nginx with Ingress without Ingress ?

推荐答案

入口规则(入口)入口控制器之间是有区别的.因此,从技术上讲,nginx入口控制器和LoadBalancer类型服务是不可比较的.您可以比较下面的入口资源和LoadBalancer类型服务.

There is a difference between ingress rule (ingress) and ingress controller. So, technically, nginx ingress controller and LoadBalancer type service are not comparable. You can compare ingress resource and LoadBalancer type service, which is below.

通常来说:

LoadBalancer类型的服务是L4(TCP)负载平衡器.您将使用它来将单个应用程序或服务公开给外界.它将根据目标IP地址和端口来平衡负载.

LoadBalancer type service is a L4(TCP) load balancer. You would use it to expose single app or service to outside world. It would balance the load based on destination IP address and port.

Ingress类型的资源将创建一个L7(HTTP/S)负载平衡器.由于L7 LB可以识别应用程序,因此您可以使用它同时公开多个服务,从而可以根据应用程序状态确定将流量发送到哪里.

Ingress type resource would create a L7(HTTP/S) load balancer. You would use this to expose several services at the same time, as L7 LB is application aware, so it can determine where to send traffic depending on the application state.

入口入口控制器关系:

ingress and ingress controller relation:

Ingressingress rulesingress controller分配负载所遵循的规则.入口控制器获取数据包,检查入口规则并确定将数据包传递到哪个服务.

Ingress, or ingress rules are the rules that ingress controller follows to distribute the load. Ingress controller get the packet, checks ingress rules and determines to which service to deliver the packet.

Nginx入口控制器

Nginx入口控制器实际上使用LoadBalancer类型的服务作为集群的入口点.然后是检查入口规则并分配负载.这可能非常令人困惑.您创建一个入口资源,它会创建HTTP/S负载平衡器.它还为您提供了一个外部IP地址(例如,在GKE上),但是当您尝试点击该IP地址时,连接将被拒绝.

Nginx ingress controller uses LoadBalancer type service actually as entrypoint to the cluster. Then is checks ingress rules and distributes the load. This can be very confusing. You create an ingress resource, it creates the HTTP/S load balancer. It also gives you an external IP address (on GKE, for example), but when you try hitting that IP address, the connection is refused.

结论:

如果您只有一个应用程序(例如myapp.com)要映射到IP地址,则可以使用Loadbalancer类型服务.

You would use Loadbalancer type service if you would have a single app, say myapp.com that you want to be mapped to an IP address.

如果要将多个应用程序(例如myapp1.commyapp1.com/mypathmyapp2.com,..,myappn.com)映射到一个IP地址,则可以使用入口资源.

You would use ingress resource if you would have several apps, say myapp1.com, myapp1.com/mypath, myapp2.com, .., myappn.com to be mapped to one IP address.

由于入口是L7,因此可以区分myapp1.commyapp1.com/mypath,可以将流量路由到正确的服务.

As the ingress is L7 it is able to distinguish between myapp1.com and myapp1.com/mypath, it is able to route the traffic to the right service.

这篇关于将Nginx暴露为负载平衡器与Ingress控制器有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆