0

Scenario: I have 2 clients. let's say client A and client B. Both clients have one common id (like UUID). My application(it's c++) is configured like both the clients have to connect in one server.

I am planning to add (AWS)ELB/nginx in front of my application. So Problem is when we received a request from client A it will pass through ELB and connect in one of the nodes. When client B sends the request to ELB then I am not sure that it will connect to the same node where client A is connected. Client B should connect on that node where Client A was connected.

IN MY SCENARIO both clients should connect to the same node. Clients always come in a pair with a common id. WHAT should use in this case?

My application is dockerized and I am using kubenetes for deployments.

  • I'm not sure if I understand you correctly. You want each client to connect to the same backend, or you want them to connect to the same node but different backends? – Crou Jan 22 '19 at 10:00
  • Thanks for helping me @Crou Clients always comes in a pair with a common id. The 1st client will connect through ELB in one node than 2nd client should connect on that node where 1st client was connected. so I want to apply ID base load balancing. – Sarjan Purohit Jan 22 '19 at 13:34
  • If you need to connect to the same node then, as I wrote you can use `nodeSelector` or `Node affinity`. – Crou Jan 22 '19 at 14:12
  • I have multiple nodes and I want to route both requests from client A and client B to the same node from the ELB. Is this possible? – Sarjan Purohit Jan 22 '19 at 14:36
  • As far as I'm aware this is possible using [sticky sessions](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-sticky-sessions.html) on ELB side. – Crou Jan 22 '19 at 14:43
  • @SarjanPurohit did you find a solution for it ? what did you end up using ? – user2225713 Mar 28 '19 at 04:13
  • @user2225713 No – Sarjan Purohit Dec 26 '19 at 07:44

1 Answers1

0

You can configure your Nginx Ingress Controller and use annotation:

nginx.ingress.kubernetes.io/server-snippet

Your Ingress might look like the following:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/server-snippet: |
 set $agentflag 0;

 if ($http_user_agent ~* "(Mobile)" ){
 set $agentflag 1;
 }

 if ( $agentflag = 1 ) {
 return 301 https://m.example.com;
 }

Please check a more detailed explanation of Annotations for ingress-nginx on Github.

If you have more than one node, you can schedule POD on the same node by using Node affinity. This can be also achieved by using nodeSelector which is a simple version of Node affinity.

Crou
  • 10,232
  • 2
  • 26
  • 31