Reputation: 169
This is a pretty basic question so I figure I must be missing something obvious, Does openshift service uses round-robin to load balance between pods? Or does it forward requests to the pod with the greatest amount of available resources? Or is it totally random?
My service configuration looks like that:
kind: service
metadata:
name: temp
labels:
app: temp
spec:
port:
targetPort: temp-port
to:
kind: Service
name: temp
Upvotes: 1
Views: 6026
Reputation: 4485
In Kubernetes (OpenShift is just a Kubernetes distribution), Services result in iptables rules. That means for a Service with more than one Pods, traffic is distributed / redirected via iptables to the different Pods selected by the Service.
So for example if we have three Pods selected by a Service, we can see the following resulting iptables entries with --probability
on the underlying Worker Nodes:
-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
So the answer to your question is that traffic distribution via a Service is random.
On the other hand, an OpenShift Route provides more control over how the traffic is distributed to the Pods. You can choose different load-balancing algorithms. Available options are source
, roundrobin
, and leastconn
.
You can find more options in the documentation about OpenShift Routes.
Upvotes: 2