Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

BKM: RTP Streaming under Kubernetes

xwu2 edited this page Dec 6, 2019 · 5 revisions

RTP streaming (from an IP camera) requires to open multiple UDP ports. This presents challenge under Kubernetes, where a service must explicitly declare any open ports (one at a time as of v1.16.) To make things worse, if the container instance is replicated (say in a Deployment), each container instance must operate at different ranges of UDP ports to avoid port conflict on the same node.

Under Kubernetes, a UDP port can be defined in multiple ways:

HostPort

We can declare a UDP port directly at the POD level:

apiVersion: apps/v1
kind: Deployment
spec:
  replicas: 1
  template:
    spec:
      containers:
        - ports:
          - containerPort:
            protocol: UDP
            hostPort: 32546

NodePort

Instead of exposing port at the POD level, we can also declare the port at the Service level:

apiVersion: v1
kind: Service
spec:
  ports:
  - port: 32546
    protocol: UDP

There are drawbacks with the above approaches:

  • Multiple Ports: As of Kubernetes v1.16, there is no support to declare a range of ports. With RTP, we need to open multiple UDP ports (each serving a video or audio stream.) We can workaround this issue utilizing m4 to generate the configuration:
apiVersion: v1
kind: Service
spec:
  ports:
forloop(`PORT',32546,32550,`dnl
  - port: defn(`PORT')
    protocol: UDP
    name: `udp'defn(`PORT')
')dnl

See Also: forloop

  • Replica Conflict: If we plan to use replicas, declaring ports at the service or POD level is not a good idea. The declared ports will cause conflict when scheduling the PODs on the same node, unless we can explicitly control which replication instance uses which port (range.) This completely defeats the purpose of using replication.

So the only viable (and happen-to-be the most reliable) solution is to use:

Host Network

TODO