WEBRTC MCU/SFU inside kubernetes - Port Ranges?
I am using janus-gateway as a webrtc media server for group videocalling. Previously I had deployed it in a single node using docker-compose but now I want to be able to scale it horizontally. For this, I am trying to use kubernetes but I am facing two problems:
1: Specifying port range to expose for the media server. As the media server needs a port range to operate, which I was able to do in docker-compose with following code
janus-gateway:
build: ./gateway
image: janus-gateway-image
restart: always
ports:
- 8088:8088
- 8188:8188
- 7088:7088
- "10000-10200:10000-10200/udp"
networks:
- back-tier
But I am unable to find any alternative for this in kubernetes. How can I expose a port range using kubernetes.
2: How can I connect from my nodejs app to a specific instance of the gateway. so let's say two instances of gateway are running, right now when user connects to the app, I connect it to one of the two instances running and save it in the redis, and make sure any request from this user is passed to that specific instance. How can I connect to specific replica from node ? Also getting replicas list?
I have checked this issue on kuebernetes but it's still not resolved yet. Is there any workaround for this?
How can I expose a port range using kubernetes.
Short answer: You cannot.
To elaborate a bit more, as Yorgos Saslis mentioned here.
the problem is that - given the current state of Docker - it seems you should NOT even be trying to expose large numbers of ports. You are advised to use the host network anyway, due to the overhead involved with large port ranges. (it adds both latency, as well as consumes significant resources - e.g. see https://www.percona.com/blog/2016/02/05/measuring-docker-cpu-network-overhead/ )
I think VoIP is not something that should be implemented with Kubernetes. media servers are pretty stateful and require dynamically opening of new connections while Kubernetes is mostly* stateless.
It would greatly depend on the actual architecture You want. But I'm assuming You want to expose a single port and let K8s do the scaling and the routing with local balancing. If statefulness of port connections is required, K8s is not the solution to use.