Skip to content

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. /healthz answers while the process runs. /readyz checks Postgres, Redis and migrations, and turns 503 when the replica is shutting down.
  • Graceful shutdown. On SIGTERM: /readyz goes 503 for http.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 in BS_NODE_API_HOSTS and BS_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=... in deploy/compose/split/node.env, then docker 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.yaml
  • database.url, database.directUrl, redis.* point at managed services; masterKey goes in a Secret (or existingSecret).
  • spa.enabled: false when the panel is on Cloudflare Pages; then list it in spaOrigins.
  • The node channel Service is a LoadBalancer with TCP on 8443.
  • Finish the setup wizard with replicaCount: 1 or with the setup code from any pod.

Nodes stay on their own servers. See Recommended architecture.

Bitstream documentation