Issue
I have an Angular frontend that I need to communicate with 2 microservices via websocket, using the same path (/socket.io
), but different ports.
I have defined this ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Values.name }}
labels:
name: {{ .Values.name }}
spec:
rules:
- host: {{ .Values.host }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ .Values.name }}-service
port:
number: {{ .Values.service.port }}
- path: /socket.io
pathType: Prefix
backend:
service:
name: spectrogram-ms-backend-service
port:
number: 8080
- path: /socket.io
pathType: Prefix
backend:
service:
name: anomaly-detection-microservice-service
port:
number: 5000
This worked fine with just the spectrogram-ms-backend-service
in place, but now with the addition of the second Websocket (for the anomaly-detection-microservice
), but I feel like it's being overridden.
Is what I want to do possible?
Solution
You have two paths defined for /socket.io
with different backend services. However, Ingress only matches the first path that satisfies the conditions. So, the connections would always be routed to the spectrogram-ms-backend-service
at port 8080
.
You can modify the config to something like this:
paths:
- path: /socket.io/{service-name}
pathType: Prefix
backend:
service:
name: {{ service-name }}-service
port:
number: {{ service-name }}-port
This way, you can achieve dynamic routing.
Just adjust Angular also:
e.g.
/socket.io/spectrogram
for the first service and /socket.io/anomaly-detection
for the second one.
Answered By - zjalicf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.