Kubernetes负载均衡HTTP/1.1请求 [英] Kubernetes load balance HTTP/1.1 requests

查看:167
本文介绍了Kubernetes负载均衡HTTP/1.1请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道,默认情况下,HTTP 1.1使用持久连接,这是一个长期连接.对于 Kubernetes 中的任何服务,例如clusterIP模式,它都是基于L4的负载均衡器.

As we know, by default HTTP 1.1 uses persistent connections which is a long-lived connection. For any service in Kubernetes, for example, clusterIP mode, it is L4 based load balancer.

假设我有一个正在运行Web服务器的服务,该服务包含3个Pod,我想知道HTTP/1.1请求是否可以分配给3个Pod?

Suppose I have a service which is running a web server, this service contains 3 pods, I am wondering whether HTTP/1.1 requests can be distributed to 3 pods?

有人可以帮助澄清吗?

推荐答案

此网页完美解决了您的问题:

This webpage perfectly address your question: https://learnk8s.io/kubernetes-long-lived-connections

本着StackOverflow的精神,让我在此处总结该网页:

In the spirit of StackOverflow, let me summarize the webpage here:

  1. TLDR:Kubernetes不会平衡长期存在的连接的负载,某些Pod可能比其他Pod收到更多的请求.

  1. TLDR: Kubernetes doesn't load balance long-lived connections, and some Pods might receive more requests than others.

Kubernetes服务不存在.没有进程可以监听服务的IP地址和端口.

Kubernetes Services do not exist. There's no process listening on the IP address and port of a Service.

服务IP地址仅用作占位符,它将通过iptables规则使用巧妙的随机化机制转换为目标容器之一的IP地址.

The Service IP address is used only as a placeholder that will be translated by iptables rules into the IP addresses of one of the destination pods using cleverly crafted randomization.

来自客户端的任何连接(无论是从内部群集还是从外部群集)都直接与Pods建立,因此对于HTTP 1.1持久连接,将在客户端与特定Pod之间维持连接,直到被POD关闭两侧.

Any connections from clients (regardless from inside or outside cluster) are established directly with the Pods, hence for an HTTP 1.1 persistent connection, the connection will be maintained between the client to a specific Pod until it is closed by either side.

因此,所有使用单个持久连接的请求都将被路由到单个Pod(在建立连接时由iptables规则选择),而不会负载均衡到其他Pod.

Thus, all requests that use a single persistent connection will be routed to a single Pod (that is selected by the iptables rule when establishing connection) and not load-balanced to the other Pods.

其他信息:

通过W3C RFC2616( https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1.3 ),在客户端和服务器之间提供服务的任何代理服务器都必须维护从客户端到自身以及从自己到服务器之间的HTTP 1.1持久连接.

By W3C RFC2616 (https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1.3), any proxy server that serves between client and server must maintain HTTP 1.1 persistent connections from client to itself and from itself to server.

这篇关于Kubernetes负载均衡HTTP/1.1请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆