Skip to content

Commit

Permalink
feat(blog): plex with socat for hdhr
Browse files Browse the repository at this point in the history
  • Loading branch information
holysoles committed Jan 29, 2025
1 parent 46b4d9b commit 71ce444
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
28 changes: 28 additions & 0 deletions blog/code_snippets/plex_with_socat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: plex
name: plex
spec:
replicas: 1
selector:
matchLabels:
app: plex
strategy:
type: Recreate
template:
metadata:
labels:
app: plex
spec:
containers:
- image: plexinc/pms-docker:1.41.3.9314-a0bfb8370
name: plex
env: [] # your env vars here
volumeMounts: [] # your volume mounts here
- image: alpine/socat:1.8.0.0
name: socat
command: ["socat", "-d", "-d", "-v", "udp4-recvfrom:65001,broadcast,fork", "udp4-sendto:192.168.20.20:65001"] # replace 192.168.20.20 with your HD Home Run's ip
volumes: [] # your volumes here
27 changes: 27 additions & 0 deletions blog/posts/2025_1_29.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
title: "Streaming Live TV with Plex and HDHomeRun inside Kubernetes"
date: "1/29/2025"
body:
- section_title: "Background"
text: "[HDHomeRuns](https://www.silicondust.com/hdhomerun/) are a great way to stream live TV to your home. These are devices produced by Silicon Dust that connect to an OTA antenna (or cable box) and can be connected to clients via USB or Ethernet.
These can be found used for pretty cheap on eBay, but even their new products are reasonably priced. What piques most folks' interest in these is their ability to integrate with Plex, allowing you to stream live TV directly within Plex clients."
- text: "In my case, I chose a Ethernet connected HDHomeRun, however this presented a challenge when running Plex inside Kubernetes. HDHomeRun connections are initiated by the client sending a UDP broadcast packet from port 65001.
This is done to discover the HDHomeRun device. Once the HDHomeRun device is discovered by the client, it will present it as a connection option, as demonstrated in [this official Plex guide](https://support.plex.tv/articles/225877347-live-tv-dvr/).
While this can easily work within a given network, what if you run your IOT devices in one VLAN, but run Plex in another? Furthermore, what if you are running Plex inside Kubernetes, which uses NAT between the pod networks and the hosts?"
- section_title: "Solution"
text: "Thankfully this is where socat (link) can help us. Socat is a versatile utility for bidirectional data transfer between two independent data streams, supporting various protocols like TCP, UDP, pipes, and files.
As [meckhert on the Unifi forum](https://community.ui.com/questions/Howto-HDHomerun-discovery-on-different-LAN-segment/97db52c6-4add-4ba1-ab0d-27ee6f43db8f) shared, socat can be used to handle the VLAN traversal.
In our case it can also handle the NATing issues from inside the Kubernetes cluster! By running socat in a sidecar container with Plex, it will be able to receive the broadcast packets Plex sends out, and forward them directly to the HDHomeRun device."
- text: "An example deployment of this:"
- code: "plex_with_socat.yaml"
- text: "Don't forget to setup any firewall rules. I found the following needed to be allowed between my IOT and Kubernetes VLANs:"
- text: "Allow HDHomeRun Discovery"
- text: "- Protocol: IPv4 UDP"
- text: "- Source: Kubernetes Host IPs"
- text: "- Destination: HDHomeRun IP"
- text: "- Destination port: 65001"
- text: "Allow HDHomeRun streaming"
- text: "- Protocol: IPv4 TCP"
- text: "- Source: Kubernetes Host IPs"
- text: "- Destination: HDHomeRun IP"
- text: "- Destination Ports: 80, 5004"
- text: "Hopefully by sharing this I can help someone else who runs into this case. Happy streaming!"

0 comments on commit 71ce444

Please sign in to comment.