Kubernetes - Load balancing Web App access per connections

4/17/2018

Long time I did not come here and I hope you're fine :)

So for now, i have the pleasure of working with kubernetes ! So let's start ! :)

[THE EXISTING]

I have an operationnal kubernetes cluster with which I work every day.it consists of several applications, one of which is of particular interest to us, which is the web management interface.

I currently own one master and four nodes in my cluster.

For my web application, pod contain 3 containers : web / mongo /filebeat, and for technical reasons, we decided to assign 5 users max for each web pod.

[WHAT I WANT]

I want to deploy a web pod on each nodes (web0,web1,web2,web3), what I can already do, and that each session (1 session = 1 user) is distributed as follows:

Users repartition

For now, all HTTP requests are processed by web0.

[QUESTIONS]

Am I forced to go through an external loadbalancer (haproxy)?

Can I use an internal loadbalancer, configuring a service?

Does anyone have experience on the implementation described above?

I thank in advance those who can help me in this process :)

-- Bat Zpk
kubernetes
kubernetes-apiserver
kubernetes-ingress

1 Answer

4/17/2018

This generally depends how and where you've deployed your Kubernetes infrastructure, but you can do this natively with a few options.

Firstly, you'll need to scale your web deployment. This is very simple to do:

kubectl scale --current-replicas=2 --replicas=3 deployment/web

If you're deployed into a cloud provider (such as AWS using kops, or GKE) you can use a service. Just specify the type as LoadBalancer. Services will spread the sessions for your users.

Another option is to use an Ingress. In order to do this, you'll need to use an Ingress Controller, such as the nginx-ingress-controller which is the most featureful and widely deployed.

Both of these options will automatically loadbalance your incoming application sessions, but they may not necessarily do it in the order you've described in your image, it'll be random across the available web deployments

-- jaxxstorm
Source: StackOverflow