Reputation: 764
I have an app which using in memory database. I created statefulset using the Pod with let's say 3 replica. used PVC for storing the database related files.
I used a Loabalancer to expose the statefulset.
So when the traffic hits loadbalancer each time it's forwarded to different pods.
Is there anyway I can control the loadbalacing to the Pod based on some condition ( like if Client IP is X go to pod Y) ?
Upvotes: 2
Views: 2929
Reputation: 950
You can use the K8s ingress resource to solve this case. I think what you're trying to do is host-based routing. Put your pods behind different services using labels. In your case 1 - 100 behind service 1, 100 - 200 behind service 2 and so on. Then create an ingress resource to redirect incoming traffic to different services based on host or path, whatever you require. You may have to use a proxy like Nginx to get this working in a public cloud platform. The YAML manifest would be something like this:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: host1.com
http:
paths:
- path: /web1
backend:
serviceName: service1
servicePort: 443
- path: /api/v1/a
backend:
serviceName: service2
servicePort: 80
- path: /api/v1/b
backend:
serviceName: service3
servicePort: 80
- host: host2.com
http:
paths:
- path: /web2
backend:
serviceName: service4
servicePort: 443
- path: /api/v2/a
backend:
serviceName: service5
servicePort: 80
Upvotes: 1
Reputation: 1651
The very fact that you have a leader/follower topology, the ask to direct traffic to a said nome (master node) is flawed for a couple of reasons:
In any case, if this is what you want, maybe you want to read about gateways in istio
which can be found here
Upvotes: 3