简体   繁体   English

将负载均衡器与 Kubernetes 一起使用

[英]Using a Load Balancer with Kubernetes

I am learning about highly available distributed systems and some of the concepts that keep coming up are load balancing (Nginx) and container orchestration (Kubernetes).我正在学习高度可用的分布式系统,并且不断出现的一些概念是负载平衡 (Nginx) 和容器编排 (Kubernetes)。 Right now my simplified understanding of them is as so:现在我对它们的简化理解是这样的:

Nginx Nginx

  • Web server that handles Http requests处理 Http 请求的 Web 服务器
  • Performs load balancing via reverse proxy to other servers (usually done in a round robin manner)通过反向代理到其他服务器执行负载平衡(通常以循环方式完成)
  • Maps a single IP (the IP of the Nginx server) to many IPs (nodes which we are load balancing over).将单个 IP(Nginx 服务器的 IP)映射到多个 IP(我们正在对其进行负载平衡的节点)。

Kubernetes Kubernetes

  • Container orchestration tool which keeps a defined state of a container cluster.容器编排工具,保留容器集群定义的 state。
  • Maps a single IP (the IP of the control plane?) to many IPs (nodes which have a container instance running on them).将单个 IP(控制平面的 IP?)映射到多个 IP(运行容器实例的节点)。

So my question is, do we use both of these tools in conjunction?所以我的问题是,我们是否同时使用这两种工具? It seems like there is some overlap?好像有些重叠?

For example, if I was creating a NodeJS app to act as a microservice which exposes a REST API, would I just simply deploy my app in a Docker container, then let Kubernetes manage it? For example, if I was creating a NodeJS app to act as a microservice which exposes a REST API, would I just simply deploy my app in a Docker container, then let Kubernetes manage it? I would not need a load balancer like Nginx in front of my Kubernetes cluster?我的 Kubernetes 集群前面不需要像 Nginx 这样的负载均衡器吗?

So my question is, do we use both of these tools in conjunction?所以我的问题是,我们是否同时使用这两种工具? It seems like there is some overlap?好像有些重叠?

You seem to have mixed a few concepts.您似乎混合了一些概念。 Don't look to much on the number of IP addresses, but more on the role of the different components.不要过多关注 IP 地址的数量,而是更多地关注不同组件的作用

Load Balancer / Gateway / Nginx负载均衡器/网关/Nginx

You probably want some form of Gateway or reverse proxy with a static known IP address (and DNS name) so that traffic from Internet can find its way to your services in the cluster.您可能需要某种形式的网关或反向代理,其static 已知 IP 地址(和 DNS 名称),以便来自 Internet 的流量可以在集群中找到通往您的服务的途径。 When using Kubernetes, it is common that your services run in a local network, but the Gateway or reverse proxy is typically the way into your cluster.使用 Kubernetes 时,您的服务通常在本地网络中运行,但网关或反向代理通常是进入集群的方式。

Kubernetes API / Control Plane Kubernetes API / 控制平面

This is an API for managing Kubernetes resources, eg deploy a new version of your apps.这是一个 API 用于管理Kubernetes 资源,例如部署新版本的应用程序。 This API is only for management / administration.此 API 仅用于管理/管理。 Your customer traffic does not use this API.您的客户流量不使用此 API。 You want to use strong authentication for this, only usable by you and your team.您想为此使用强身份验证,只有您和您的团队才能使用。 Pods in your cluster can use this API, but they need a Service Account and proper RBAC Authorization .集群中的 Pod可以使用这个 API,但它们需要一个服务帐户和适当的RBAC 授权

Kubernetes gives you a self-contained/sandboxed environment where your services are safe from the outside world running on private non-routable subnets. Kubernetes 为您提供了一个自包含/沙盒环境,您的服务在私有不可路由子网上运行时不受外界影响。 Because pods are ephemeral, their IPs can change anytime.因为 pod 是短暂的,所以它们的 IP 可以随时更改。 Hence, Kubernetes has a "Service" concept.因此,Kubernetes 具有“服务”概念。 Different micro-services interact with each other using servicename:port so that they don't have to worry about the POD IPs.不同的微服务使用 servicename:port 相互交互,因此它们不必担心 POD IP。

However,if you want to access your application from outside (internet) you need to configure an ingress controller.但是,如果您想从外部(互联网)访问您的应用程序,您需要配置一个入口 controller。 This ingress controller can be implemented using Nginx.这个入口 controller 可以使用 Nginx 来实现。

So, your ingress controller (nginx) will receive request and send it to the service, which can load balance it to the pods to meet the desired state.因此,您的入口 controller (nginx) 将接收请求并将其发送到服务,该服务可以将其负载平衡到 pod 以满足所需的 state。

In large system, the nginx ingress controllers may need to scale as well to serve the incoming requests.在大型系统中,nginx 入口控制器可能还需要扩展以服务传入请求。

So, long story short, you will need both if you want to scale and for routing purposes.所以,长话短说,如果你想扩展和路由目的,你将需要两者。

The short answer to your question is yes you need a load balancer in front of your Kubernetes cluster to route external traffic to the services of your application in the cluster or your application will not be accessible from outside.对您的问题的简短回答是,您需要在 Kubernetes 集群前面安装一个负载均衡器,以将外部流量路由到集群中应用程序的服务,否则您的应用程序将无法从外部访问。

Basically, Kubernetes provides built‑in HTTP load balancing with Ingress which is API object that describes the desired state for exposing services to the outside of the Kubernetes cluster (check this this_Link for more infos about Ingress). Basically, Kubernetes provides built‑in HTTP load balancing with Ingress which is API object that describes the desired state for exposing services to the outside of the Kubernetes cluster (check this this_Link for more infos about Ingress).

Simply, Kubernetes alone is capable to deal with the whole state of your application including loadBalancing.简单地说,仅 Kubernetes 就能够处理您的应用程序的整个 state,包括负载平衡。

For advanced microservices architechture Nginx developed an Ingress Controller extension for Kubernetes Load Balancing which presents the Nginx features in the Ingress K8s API. For advanced microservices architechture Nginx developed an Ingress Controller extension for Kubernetes Load Balancing which presents the Nginx features in the Ingress K8s API.

For more Informations about Nginx and Nginx Plus for Kubernetes Ingress check link bellow:有关 Nginx 和 Nginx Plus 的更多信息,用于 Kubernetes 入口检查链接如下:

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

相关问题 在 Kubernetes 中使用 traefik 作为负载均衡器的问题 - Problem using traefik as load balancer in Kubernetes 检查 Kubernetes 中的负载均衡器 - Check Load Balancer in Kubernetes Kubernetes - 使用单个负载均衡器对多个服务进行负载均衡 - Kubernetes - load balance multiple services using a single load balancer 如何在 Kubernetes 中使用负载均衡器服务公开多个端口 - How to expose multiple port using a load balancer services in Kubernetes 在Kubernetes中使用externalIP作为服务在内部使用网络负载平衡器 - Using externalIP as a service in kubernetes for on premise with network load balancer 使用 kubeadm 创建 Kubernetes 集群时 kubeapi 服务器的负载均衡器 - Load balancer for kubeapi server while creating the Kubernetes cluster using kubeadm 使用自托管 nginx 作为 kubernetes-apiserver 负载均衡器 - using self hosted nginx as kubernetes-apiserver load balancer 如何使用负载均衡器向外界公开 kubernetes 服务 - how to expose a kubernetes service for outside world using load balancer 使用负载均衡器时在 kubernetes 日志中查看客户端 IP 地址 - View client ip address in kubernetes logs when using load balancer Kubernetes-在HA中运行负载平衡器并使用DNS访问应用程序 - Kubernetes - Running load balancer in HA and using DNS to access application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM