Appearance
Several control replicas
bs-control can run as 2 or more replicas on the same Postgres and Redis, behind a load balancer. Kubernetes is optional, never required.
What makes it safe
- No local state required. The master key comes from
BS_MASTER_KEY(or a mounted file). The node CA and certificates live encrypted in the database. The data dir only holds caches and local backup files (mount a shared volume, or copy backups off site, if you keep backups on disk). - Migrations run once. The first replica takes a Postgres advisory lock and migrates; the others wait and find nothing to do.
- Scheduled jobs run once. Backups, the license check-in, EPG refresh, TMDB matching and certificate renewal run on one replica, chosen with a Redis lock (
bs:leader:{job}). If it dies, another takes over in 30 seconds. Logs, GeoIP and module jobs keep their own per-run locks. - Node commands reach the right replica. A node keeps one channel to one replica. That replica records itself in
bs:node:{id}:owner. An action on another replica (restart a stream, probe, kill a viewer) is sent over Redis to the owner, which delivers it and sends the answer back. Every replica shows the node online. - Health.
/healthzanswers while the process runs./readyzchecks Postgres, Redis and migrations, and turns 503 when the replica is shutting down. - Graceful shutdown. On SIGTERM:
/readyzgoes 503 forhttp.drain_delay, then requests in flight finish (up to 20 s). Node channels close and the nodes reconnect to another replica within seconds. - Setup code. It is stored in the database, so any replica accepts it.
Load balancer
- HTTP
:8080(or:443): any HTTP balancer. Long requests stream (proxy mode, playlists), so turn response buffering off. - Node channel
:8443: TCP passthrough, never TLS termination. mTLS ends on the replica. Put the balancer name inBS_NODE_API_HOSTSandBS_NODE_API_PUBLIC_URL. - Trust the balancer: add its addresses to
BS_HTTP_TRUSTED_PROXIES.
Try it with Docker Compose
deploy/compose/split/ runs two replicas behind nginx, Postgres, Redis, the panel as static files on another origin, and one node:
bash
docker build -f deploy/docker/Dockerfile --target control -t bitstream/control:dev .
docker build -f deploy/docker/Dockerfile --target node -t bitstream/node:dev .
(cd web && pnpm build)
docker compose -f deploy/compose/split/docker-compose.yml up -d- API:
http://api.localhost:18080, panel:http://api.localhost:18081(another origin on the same site). - The setup code:
docker cp bitstream-split-control-a-1:/data/setup.code -. - Create a join token in the panel (Servers, Add), put
BS_JOIN_TOKEN=...indeploy/compose/split/node.env, thendocker compose -f deploy/compose/split/docker-compose.yml --profile node up -d node. - Clean up:
docker compose -f deploy/compose/split/docker-compose.yml --profile node down -v.
Images are distroless and run as a non-root user. The control image is the API only.
Kubernetes (optional)
deploy/helm/bitstream-control deploys the control only:
bash
helm install bs deploy/helm/bitstream-control -f my-values.yamldatabase.url,database.directUrl,redis.*point at managed services;masterKeygoes in a Secret (orexistingSecret).spa.enabled: falsewhen the panel is on Cloudflare Pages; then list it inspaOrigins.- The node channel Service is a
LoadBalancerwith TCP on 8443. - Finish the setup wizard with
replicaCount: 1or with the setup code from any pod.
Nodes stay on their own servers. See Recommended architecture.