gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 12:12:05 32 4
gpt4 key购买 nike

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

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

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

    Why do we need a loadbalancer? It is not meant to load balance across multiple instances. It will justforward all the traffic to nginx reverse proxy created and it willroute 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/

    32 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com