Skip to content

加载 Balancer

一句话解释

加载 balancer distributes incoming network traffic 跨越多个服务器到 ensure reliability and 性能.

用大白话说

A load balancer sits in front of your servers and distributes incoming requests across them. If you have 3 web servers, the load balancer sends each new request to a different server, spreading the load evenly.

Load balancers improve availability — if one server fails, the load balancer stops sending traffic to it and routes to the healthy servers. They also improve performance — by spreading requests, no single server gets overwhelmed.

There are two main types: Layer 4 (transport layer — distributes based on IP and port) and Layer 7 (application layer — can route based on HTTP path, headers, cookies). Common algorithms are round-robin, least connections, and IP hash.

示例

yaml
apiVersion: v1
kind: Service
metadata:
  name: my-app-lb
spec:
  type: LoadBalancer
  selector:
    app: my-app
  ports:
    - port: 80
      targetPort: 8080

这个 Kubernetes Service 的类型 LoadBalancer provisions cloud 加载 balancer 那个 distributes traffic 到 Pods.

工作原理

  1. A client sends a request to the load balancer's address.
  2. The load balancer picks a healthy backend server using an algorithm.
  3. It forwards the request to that server.
  4. The server's response goes back through the load balancer to the client.

常见混淆

  • 容易混淆的对象: Reverse Proxy

    关键区别: 加载 balancer distributes traffic 跨越服务器; reverse proxy sits in 前面的 服务器 and 能也 handle 缓存, TLS, and routing. 许多加载 balancers 也 act as reverse proxies.

相关术语

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表