如何使 kube-proxy 均匀分发负载?

huangapple go评论70阅读模式
英文:

How to make kube-proxy is distribute the load evently?

问题

我有一个ClusterIP服务,用于在内部分发负载到2个POD。
负载没有均匀分发到这2个POD上。
如何使负载均匀分发?

英文:

I have a ClusterIP Service which is used to distribute load to 2 PODs internally.
The load is not distributed evenly across the PODs.

How to make the load distributed evenly ?

答案1

得分: 1

Kubernetes使用iptables来在Pod之间分发负载(默认情况下使用iptables代理模式)。

如果有2个Pod,负载会均匀分布,概率为0.5(50%)。因为它不使用循环轮询,后端Pod是随机选择的。在较长的时间范围内,它将保持均匀。

如果有3个Pod,概率将变为1/3(33%),对于4个Pod,概率为1/4,依此类推。

要检查它,您可以运行 sudo iptables-save

2个Pod的示例输出(对于nginx服务):

sudo iptables-save | grep nginx

-A KUBE-NODEPORTS -p tcp -m comment --comment "default/nginx:" -m tcp --dport 31554 -j KUBE-SVC-4N57TFCL4MD7ZTDA	//KUBE-SVC-4N57TFCL4MD7ZTDA是nginx服务的标签

sudo iptables-save | grep KUBE-SVC-4N57TFCL4MD7ZTDA
-A KUBE-SVC-4N57TFCL4MD7ZTDA -m statistic --mode random --probability 0.50000000000 -j KUBE-SEP-SOWYYRHSSTWLCRDY

如果您希望确保负载均匀分布,使用循环轮询算法,您可以使用IPVS,默认情况下使用rr(循环轮询)。它作为集群前端的负载均衡器,将基于TCP和UDP的服务的请求引导到真实服务器,并使真实服务器的服务出现为单个IP地址上的虚拟服务。它在由local-up、kubeadm和GCE创建的集群上是受支持的

英文:

Kubernetes uses iptables to distribute the load between pods (iptables proxy mode by default).

If you have 2 pods, it is distributed evenly with 0.5 (50%) probability. Because it is not using round-robin, the backend pod is chosen randomly. It will be even in a longer time-frame.

If there would be 3 pods, probability will change to 1/3 (33%), for 4 pods 1/4 and so on.

To check it you can run sudo iptables-save.

Example output for 2 pods (for nginx service):

sudo iptables-save | grep nginx

-A KUBE-NODEPORTS -p tcp -m comment --comment "default/nginx:" -m tcp --dport 31554 -j KUBE-SVC-4N57TFCL4MD7ZTDA	//KUBE-SVC-4N57TFCL4MD7ZTDA is a tag for nginx service

sudo iptables-save | grep KUBE-SVC-4N57TFCL4MD7ZTDA
-A KUBE-SVC-4N57TFCL4MD7ZTDA -m statistic --mode random --probability 0.50000000000 -j KUBE-SEP-SOWYYRHSSTWLCRDY

If you want to make sure load is distributed evenly using round-robin algorithm you can use IPVS which by default uses rr (round-robin). It works as load balancer in front of a cluster and directs requests for TCP- and UDP-based services to the real servers, and make services of the real servers appear as virtual services on a single IP address. It is supported on cluster created by local-up, kubeadm and GCE.

答案2

得分: 0

kube-proxy 在用户空间代理模式下通过轮询方式选择后端 Pod。

kube-proxy 在 iptables 模式下随机选择后端 Pod。

英文:

kube-proxy in User space proxy mode chooses backend pod via round robin fashion.

kube-proxy in iptables mode chooses the backend pod randomly.

huangapple
  • 本文由 发表于 2020年1月6日 17:53:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609914.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定