Mediamtx webrtc stream is not accessible while running inside k8s cluster in minikube
I am facing an issue while trying to access a MediaMTX WebRTC stream that is deployed inside a Minikube Kubernetes cluster. The deployment seems to be set up correctly, but I cannot access the WebRTC stream, and I am getting a timeout error when trying to establish a connection.
Steps to Replicate the Issue:
-
Create a Minikube Cluster: Set up a Minikube cluster using the default configuration.
-
Deploy MediaMTX: Deploy the following resources: a Deployment, a Service, and a ConfigMap.
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" # Adjust as needed
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: |
paths:
mycamera:
source: rtsp://admin:[email protected]:554/unicaststream/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.
-
Apply all resources, wait for medamtx pod to start. Expose mediamtx service using kubectl port-forward
-
Now the webrtc stream should be accessible at http://localhost:8889/mycamera, But I am not able to access it
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
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