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

查看:29
本文介绍了将 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. 服务类型设置为LoadBalancer瞧,我得到了公共IP
  2. 使用 Nginx 入口控制器
  1. Set service type as LoadBalancer voila I got public IP
  2. Use Nginx Ingress Controller

现在我可以使用选项 1 完成我的工作,什么时候或为什么我会选择选项 2 使用带有 Ingress 的 nginx 而没有 Ingress 的优势是什么?

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 ?

推荐答案

入口规则(ingress)入口控制器是有区别的.所以,从技术上讲,nginx ingress controller 和 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天全站免登陆