Dynamic URL that forwards all requests to dedicated Pod in Kubernetes

6/18/2020

I am trying to use a kubernetes cluster to do on-demand live transcoding of a video stream from multiple ip cameras, and send via websocket to a website.

I've modified a project I found online written in go, which takes a web request with a payload of the rtsp feed URL, it then uses the url to start a FFMPEG process to access the stream and transcode it to MPEG and sends the mpeg data to another endpoint on the go app, which starts a websocket connection. The response to the orignal request includes a websocket url when the stream can be accessed. Which the url can be put into a mpeg js player and viewed in a browser over the websocket. Main advantage is multiple clients can view the stream while there is only one stream coming from camera which reduces mobile data. I will also add that the FFMPEG automatically stops after 60 seconds with a request isn't set to endpoint.

The problem I can't find a solution to, is how can I scale the above application in a kubernetes cluster, so when I request comes in it does the below. -> Checks to see if someone is already viewing stream <br> ----> If someone is viewing, means a pod and websocket connection is already created. So a url that points to the pod just needs to be sent back to client.<br> ----> If no one is viewing, a streaming/websocket pod needs to be created and once created a url sent back to the client to access stream. <br>

I've looked at ingress controllers possibly dynamically updating the ingress resource is a solution, or even possible using a service mesh, but these are all new to me.

If anyone has any input to give me a bit of direction down a path, it would be much appreciated.

Many Thanks Luke

-- lukerobbo
go
kubernetes
kubernetes-ingress
video-streaming
websocket

1 Answer

6/18/2020

Having your application dynamically configure K8s sounds like a complicated solutions with possible performance implications due to a very large object of ingress objects. You might have to look into how to clean those up. Also, doing this requires a K8s client in your app.

I would suggest to solve this without the help of K8s resources by simply having your application return a HTTP redirect (301) to that websocket URL if need be.

-- Fritz Duchardt
Source: StackOverflow