I need to be able to split traffict to two backend pods in a cluster, based on this schematic for a university project:
So Far, I have accomplished this diagram and progress:
All other parts of the project work fine. The part I'm having difficulty understanding is how to split traffic evenly between de gRPC-Client (a backend in node) and Redis Pub (a backend in Golang). I tried applying some configurations with ingress, gateways, but nothing has worked. I'm pretty sure it has to be with a load balancer but I cannot get it to work. I also read something about nginx service but I couldn't work that one either.
The behaivor should be this:
1)Front end consumes API at http://some-ip:3000/ (the ip is not necessary to be static, and port 3000 is not strictly 3000, it can be any port)
2)Traffic from incoming clients consuming the API gets split in half between the gRPC-client backend and the Redis-pub backend
This is my configuration for both backend pods:
gRPC Backend
#gRPC
apiVersion: apps/v1
kind: Deployment
metadata:
name: grpc-deployment
labels:
app: grpc
namespace: so1
spec:
selector:
matchLabels:
app: grpc
replicas: 1
template:
metadata:
labels:
app: grpc
spec:
containers:
- name: grpc-server
image: 'gcr.io/so1-proyecto-383722/grpc_server:latest'
ports:
- containerPort: 50051
- name: grpc-client
image: 'gcr.io/so1-proyecto-383722/grpc_client:latest'
ports:
- containerPort: 50061
---
#gRPC Server Service
apiVersion: v1
kind: Service
metadata:
name: grpc-service
labels:
app: grpc
namespace: so1
spec:
selector:
app: grpc
type: ClusterIP
ports:
- name: grpc
port: 50051
targetPort: 50051
---
#gRPC Client Service (For Traffict Split)
apiVersion: v1
kind: Service
metadata:
name: input-grpc-service
labels:
app: input-service
namespace: so1
spec:
selector:
app: grpc
type: ClusterIP
ports:
- name: grpc
port: 3000 #3000
targetPort: 50061
Redis Backend
#Redis Pub Sub
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-pub-sub-deployment
labels:
app: redis-pub-sub
namespace: so1
spec:
selector:
matchLabels:
app: redis-pub-sub
replicas: 1
template:
metadata:
labels:
app: redis-pub-sub
spec:
containers:
- name: redis-pub
image: 'gcr.io/so1-proyecto-383722/redispub:latest'
ports:
- containerPort: 11000
- name: redis-sub
image: 'gcr.io/so1-proyecto-383722/redissub:latest'
---
#Redis Pub Service (For Traffict Split)
apiVersion: v1
kind: Service
metadata:
name: input-redis-service
labels:
app: input-service
namespace: so1
spec:
selector:
app: redis-pub-sub
type: ClusterIP
ports:
- name: redis-pub-sub
port: 3000 #3000
targetPort: 11000
Could anyone help me follow the right direction or give me an example that can work for this? Appreciate any help.