kubernetes - 为什么我们需要一个负载均衡器来使用 ingress 暴露 kubernetes 服务?

标签 kubernetes google-cloud-platform load-balancing google-kubernetes-engine kubernetes-ingress

对于部署在 Google kubernetes 引擎上的基于微服务的示例架构,我需要帮助来验证我的理解:

  • 我们知道服务应该对 pod 副本集的流量进行负载平衡。
  • 当我们创建一个 nginx 入口 Controller 和入口定义以路由到每个服务时,也会自动设置一个负载均衡器。
  • 在某处读到创建 nginx 入口 Controller 意味着 nginx Controller (部署)和在幕后创建的负载均衡器类型服务。我不确定这是否属实。

  • It seems loadbalancing is being done by services. URL based routing is being done by ingress controller.

    Why do we need a loadbalancer? It is not meant to load balance across multiple instances. It will just forward all the traffic to nginx reverse proxy created and it will route requests based on URL.


    如果我的理解有误,请纠正。

    最佳答案

    服务类型LoadBalancerIngress是从外部访问您的应用程序的方式,尽管它们以不同的方式工作。

    Service:

    In Kubernetes, a Service is an abstraction which defines a logical set of Pods and a policy by which to access them (sometimes this pattern is called a micro-service). The set of Pods targeted by a Service is usually determined by a selector (see below for why you might want a Service without a selector).



    有一些类型的服务,其中有 LoadBalancer允许您在外部公开您的应用程序并为您的服务分配外部 IP 的类型。对于每个 LoadBalancer 服务,都会为其分配一个新的外部 IP。
    负载均衡将由 kube-proxy 处理。

    Ingress:

    An API object that manages external access to the services in a cluster, typically HTTP. Ingress may provide load balancing, SSL termination and name-based virtual hosting.



    当您设置入口(即:nginx-ingress)时,服务类型 LoadBalancer为 ingress-controller pods 创建并自动创建云提供商中的负载均衡器,并将为 nginx-ingress 服务分配公共(public) IP。

    此负载均衡器/公共(public) ip 将用于所有服务的传入连接,而 nginx-ingress 将负责处理传入连接。

    例如:

    假设您有 LoadBalancer 的 10 个服务类型:这将导致创建 10 个新的公共(public) ip,您需要将对应的 ip 用于您想要访问的服务。

    但是,如果您使用入口,则只会创建 1 个 IP,并且入口将负责根据您在入口配置中定义的 PATH/URL 为正确的服务处理传入连接。通过 ingress,您可以:
  • path 中使用正则表达式定义要重定向的服务;
  • 使用 SSL/TLS
  • 注入(inject)自定义 header ;
  • 如果其中一项服务失败(默认后端),则重定向对默认服务的请求;
  • 根据IP创建白名单
  • 等等...

  • 一个重要的note关于 Ingress 中的 Ingress 负载均衡:

    GCE/AWS load balancers do not provide weights for their target pools. This was not an issue with the old LB kube-proxy rules which would correctly balance across all endpoints.

    With the new functionality, the external traffic is not equally load balanced across pods, but rather equally balanced at the node level (because GCE/AWS and other external LB implementations do not have the ability for specifying the weight per node, they balance equally across all target nodes, disregarding the number of pods on each node).

    关于kubernetes - 为什么我们需要一个负载均衡器来使用 ingress 暴露 kubernetes 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61485529/

    相关文章:

    docker - 如何为 Kubernetes 桌面 UI 配置简单的登录/通过身份验证

    kubernetes - 通过Istio Gateway/VirtualService公开开源Helm图表

    google-cloud-platform - 无论如何,我可以将抢占式实例用于数据流作业吗?

    ssl - 将 Comodo SSL 与 AWS 证书链结合使用

    python - Gunicorn 一次响应的请求不超过 6 个

    curl - 无法打开 tcp :8080 port on Google Cloud

    excel - 是否可以通过 Google Script 填写 PDF 表单?或者通过云端的 Google Script 在 PDF 上添加文本?

    tomcat - Microsoft Azure 负载平衡虚拟机中的集群 Tomcat JasperServer

    Azure 传统负载均衡器 VS Azure 应用程序网关响应延迟?

    kubernetes - Pod 处于待处理阶段(错误 : FailedScheduling : nodes didn't match node selector )