Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Access Mediamtx webrtc stream inside k8s cluster - Minikube #3799

Closed
12 tasks
phadkesharan opened this issue Sep 24, 2024 · 2 comments
Closed
12 tasks

Comments

@phadkesharan
Copy link

Which version are you using?

v0.0.0

Which operating system are you using?

  • Linux amd64 standard
  • [x ] Linux amd64 Docker
  • Linux arm64 standard
  • Linux arm64 Docker
  • Linux arm7 standard
  • Linux arm7 Docker
  • Linux arm6 standard
  • Linux arm6 Docker
  • Windows amd64 standard
  • Windows amd64 Docker (WSL backend)
  • macOS amd64 standard
  • macOS amd64 Docker
  • Other (please describe)

Describe the issue

Mediamtx webrtc stream is not accessible while running inside k8s cluster in minikube

Describe how to replicate the issue

  1. Create minikube cluster.
  2. Deploy mediamtx Deployment, Service and Config Map

The Config map include custom mediamtx.yml config

Mediamtx Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
name: mediamtx
labels:
app: mediamtx
spec:
replicas: 1
selector:
matchLabels:
app: mediamtx
template:
metadata:
labels:
app: mediamtx
spec:
containers:
- name: mediamtx
image: bluenviron/mediamtx
args: ["/mediamtx.yml"] # Explicitly specify the config file location
volumeMounts:
- name: config
mountPath: /mediamtx.yml
subPath: mediamtx.yml
ports:
- containerPort: 8554
- containerPort: 1935
- containerPort: 8888
- containerPort: 8889
- containerPort: 8890
- containerPort: 8189
env:
- name: MTX_PROTOCOLS
value: "tcp"
- name: MTX_WEBRTCADDITIONALHOSTS
value: "172.19.0.1"

  volumes:
  - name: config
    configMap:
      name: mediamtx-config
      defaultMode: 0644  # Ensure the file is readable

Mediamtx Service

apiVersion: v1
kind: Service
metadata:
name: mediamtx
spec:
type: ClusterIP
ports:

  • name: rtsp
    port: 8554
    targetPort: 8554
    protocol: TCP
  • name: rtmp
    port: 1935
    targetPort: 1935
    protocol: TCP
  • name: web
    port: 8888
    targetPort: 8888
    protocol: TCP
  • name: web-rtc
    port: 8889
    targetPort: 8889
    protocol: TCP
  • name: rtsp-udp
    port: 8890
    targetPort: 8890
    protocol: UDP
  • name: udp-extra
    port: 8189
    targetPort: 8189
    protocol: UDP
    selector:
    app: mediamtx

mediamtx config map

apiVersion: v1
kind: ConfigMap
metadata:
name: mediamtx-config
data:
mediamtx.yml: |
# Your custom MediaMTX configuration goes here
# webrtcICEServers2:
# - url: stun:stun2.1.google.com:19302

paths:
  # example:
  mycamera:
    source: rtsp://admin:[email protected]:554/unicaststream/1

  all_others:
  1. The Config map includes custom mediamtx configuration. I have added a default rtsp stream path entry to it, And trying to access the corresponding webrtc streams.

  2. Apply all resources, wait for medamtx pod to start. Expose mediamtx service using kubectl port-forward

  3. Now the webrtc stream should be accessible at http://localhost:8889/mycamera, But I am not able to access it

Did you attach the server logs?

Mediamtx server logs before trying to access webrtc stream
2024/09/24 06:49:37 INF MediaMTX v1.9.0
2024/09/24 06:49:37 INF configuration loaded from /mediamtx.yml
2024/09/24 06:49:37 INF [path matrixcamera] [RTSP source] started
2024/09/24 06:49:37 INF [RTSP] listener opened on :8554 (TCP)
2024/09/24 06:49:37 INF [RTMP] listener opened on :1935
2024/09/24 06:49:37 INF [HLS] listener opened on :8888
2024/09/24 06:49:37 INF [WebRTC] listener opened on 0.0.0.0:8889 (HTTP), :8189 (ICE/UDP)
2024/09/24 06:49:37 INF [SRT] listener opened on :8890 (UDP)
2024/09/24 06:49:37 INF [path matrixcamera] [RTSP source] ready: 2 tracks (H264, G711)

Mediamtx server logs after trying to access webrtc stream
2024/09/24 07:15:24 INF [WebRTC] [session 8b9d0424] created by 127.0.0.1:52060
2024/09/24 07:15:34 INF [WebRTC] [session 8b9d0424] closed: deadline exceeded while waiting connection

I am trying to access the stream at localhost:8889/mycamera after running kubectl port-forward svc/mediamtx 8889:8889

yes / no

Did you attach a network dump?

yes / no

I also tried adding stun/turn server in mediamtx config
# webrtcICEServers2:
# - url: stun:stun2.1.google.com:19302

Also tried adding webrtc address as broadcast in mediamtx config
# rtspAddress: 0.0.0.0:8554

Still I am unable to acesss I get following errrors in browser console

   DELETE http://localhost:8889/matrixcamera/whep/adcf8e30-a171-4843-bfa0-8b2522b86abe 404 (Not Found)

onError @ matrixcamera/:368
onConnectionState @ matrixcamera/:490
pc.oniceconnectionstatechange @ matrixcamera/:515
favicon.ico:1

The whep DELETE request always timesout

@LastSkywalkerER
Copy link

Have same issue

@aler9
Copy link
Member

aler9 commented Oct 7, 2024

As written in the README:

If there's a NAT / container between server and clients, it must be configured to route all incoming UDP packets on port 8189 to the server

If you use kubectl port-forward svc/mediamtx 8889:8889, you are just exposing TCP port 8889, not UDP port 8189. You have to expose both ports and provide a valid address inside webrtcAdditionalHosts. There are several methods to do this but this is a Kubernetes-related question, not a server bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants