pods之间openshift服务如何负载均衡?
How openshift service loadbalance between pods?
这是一个非常基本的问题,所以我想我一定遗漏了一些明显的东西,openshift 服务是否使用循环法在 pods 之间进行负载平衡?还是将请求转发给可用资源最多的 pod?还是完全随机?
我的服务配置如下所示:
kind: service
metadata:
name: temp
labels:
app: temp
spec:
port:
targetPort: temp-port
to:
kind: Service
name: temp
在 Kubernetes 中(OpenShift 只是一个 Kubernetes 发行版),Services 导致 iptables 规则。这意味着对于具有多个 Pods 的服务,流量通过 iptables 分发/重定向到服务选择的不同 Pods。
因此,例如,如果我们有一个服务选择了三个 Pods,我们可以在底层工作节点上看到以下带有 --probability
的 iptables 条目:
-A KUBE-SVC-C5D5TE7O3IX6LYPU -m comment --comment "openshift-logging/fluentd:metrics" -m statistic --mode random --probability 0.20000000019 -j KUBE-SEP-K7BWKR3YFNRALYRO
-A KUBE-SVC-C5D5TE7O3IX6LYPU -m comment --comment "openshift-logging/fluentd:metrics" -m statistic --mode random --probability 0.25000000000 -j KUBE-SEP-SLOSD6E2CHTNQQZ7
-A KUBE-SVC-C5D5TE7O3IX6LYPU -m comment --comment "openshift-logging/fluentd:metrics" -m statistic --mode random --probability 0.33333333349 -j KUBE-SEP-I2MJAF47DZ7EPTNC
-A KUBE-SVC-C5D5TE7O3IX6LYPU -m comment --comment "openshift-logging/fluentd:metrics" -m statistic --mode random --probability 0.50000000000 -j KUBE-SEP-QCINKYOFNQTK2FRX
-A KUBE-SVC-C5D5TE7O3IX6LYPU -m comment --comment "openshift-logging/fluentd:metrics" -j KUBE-SEP-RWL5ZKQM57XO3TAF
所以你的问题的答案是通过服务的流量分配是随机的。
另一方面,OpenShift 路由可以更好地控制流量分配到 Pods 的方式。您可以选择不同的负载平衡算法。可用选项有 source
、roundrobin
和 leastconn
。
您可以在 documentation about OpenShift Routes.
中找到更多选项
这是一个非常基本的问题,所以我想我一定遗漏了一些明显的东西,openshift 服务是否使用循环法在 pods 之间进行负载平衡?还是将请求转发给可用资源最多的 pod?还是完全随机?
我的服务配置如下所示:
kind: service
metadata:
name: temp
labels:
app: temp
spec:
port:
targetPort: temp-port
to:
kind: Service
name: temp
在 Kubernetes 中(OpenShift 只是一个 Kubernetes 发行版),Services 导致 iptables 规则。这意味着对于具有多个 Pods 的服务,流量通过 iptables 分发/重定向到服务选择的不同 Pods。
因此,例如,如果我们有一个服务选择了三个 Pods,我们可以在底层工作节点上看到以下带有 --probability
的 iptables 条目:
-A KUBE-SVC-C5D5TE7O3IX6LYPU -m comment --comment "openshift-logging/fluentd:metrics" -m statistic --mode random --probability 0.20000000019 -j KUBE-SEP-K7BWKR3YFNRALYRO
-A KUBE-SVC-C5D5TE7O3IX6LYPU -m comment --comment "openshift-logging/fluentd:metrics" -m statistic --mode random --probability 0.25000000000 -j KUBE-SEP-SLOSD6E2CHTNQQZ7
-A KUBE-SVC-C5D5TE7O3IX6LYPU -m comment --comment "openshift-logging/fluentd:metrics" -m statistic --mode random --probability 0.33333333349 -j KUBE-SEP-I2MJAF47DZ7EPTNC
-A KUBE-SVC-C5D5TE7O3IX6LYPU -m comment --comment "openshift-logging/fluentd:metrics" -m statistic --mode random --probability 0.50000000000 -j KUBE-SEP-QCINKYOFNQTK2FRX
-A KUBE-SVC-C5D5TE7O3IX6LYPU -m comment --comment "openshift-logging/fluentd:metrics" -j KUBE-SEP-RWL5ZKQM57XO3TAF
所以你的问题的答案是通过服务的流量分配是随机的。
另一方面,OpenShift 路由可以更好地控制流量分配到 Pods 的方式。您可以选择不同的负载平衡算法。可用选项有 source
、roundrobin
和 leastconn
。
您可以在 documentation about OpenShift Routes.