Thanks — I’ll explain the self‑hosted LiveKit architecture on Kubernetes and how a Python agent app fits in. A few quick questions so I tailor this correctly:
• Do you plan a single-node cluster (dev) or multi‑node production with high availability?
• Will the Python agent be long‑running workers that join rooms, or short‑lived per‑job pods?
• Which cloud/ingress (GKE, EKS, DigitalOcean) and do you need embedded TURN or an external TURN?
High‑level architecture
• LiveKit servers (SFU): Deployed via Helm as a DaemonSet/Deployment. Pods handle WebRTC media routing. For host‑networking deployments, one LiveKit pod runs per node.
• Redis cluster: Used for state coordination and message bus across LiveKit nodes for distributed routing and stats.
• Ingress & TLS: Ingress controller (ALB/NGINX) terminates TLS; Helm values configure domain and TLS certs (ACM or cert‑manager).
• TURN server: TURN/TLS enabled (embedded or external) to improve connectivity for restrictive networks.
• Persistent storage / logging / metrics: Use Prometheus + Grafana for metrics, and EFK/Opensearch for logs. Connection draining ensures graceful pod restarts so active rooms continue while new joins are blocked.
• Helm / values.yaml: Configure LiveKit via the provided Helm chart and a custom values.yaml (service type, hostNetwork, Redis addresses, TURN, worker counts, TLS).
Python agent placement and behavior
• Separate deployment: Run your Python agent as its own Deployment (or Autoscaled HorizontalPodAutoscaler). Agents act as normal LiveKit participants that join rooms.
• Worker model options:
◦ Long‑running agents: One pod subscribes to jobs and joins many rooms sequentially or concurrently.
◦ Per‑job ephemeral pods: A controller creates a pod per job/room that joins, processes, then exits.
• Scaling: Scale agent replicas independently from LiveKit SFU nodes. Use HPA based on CPU, memory, or custom metrics (e.g., active rooms).
• Networking: Agents connect to LiveKit via the same ingress/TURN endpoints as clients. If agents run inside the same cluster, use ClusterIP service DNS for lower latency.
• Media handling: Use the LiveKit Agents SDK for Python to join rooms, process incoming audio/video, and publish responses (TTS/STT/LLMs). Containerize the agent (Docker) and run under a non‑privileged user.
• Secrets & config: Store API keys, STT/TTS/LLM creds in Kubernetes Secrets; config via ConfigMaps or environment variables.
Suggested Kubernetes resources
• LiveKit Helm chart (Deployment/DaemonSet), configured hostNetwork if required.
• Redis StatefulSet/Cluster (or managed Redis).
• Ingress (ALB/NGINX) + cert‑manager or cloud cert manager.
• TURN: either enable LiveKit’s embedded TURN or deploy coturn as a Service.
• Python agent Deployment with HPA, ServiceAccount, RBAC, and Liveness/Readiness probes.
• Optional: Job/Controller for ephemeral agent pods (Kubernetes Jobs or a custom controller).
Operational considerations
• Capacity planning: SFU CPU/network bound — size nodes for media throughput, not just connections.
• Node placement: hostNetwork requirement limits one LiveKit pod per node; plan node count accordingly.
• Graceful shutdown: Use connection draining so active rooms remain stable during rolling updates.
• Monitoring: Collect SFU metrics and agent metrics; alert on high packet loss, CPU, or connection drops.
• Cost/availability: Consider managed Redis and TURN if you want lower operational overhead.
If you want, I can:
• Provide an example values.yaml for the Helm chart tuned for production on your chosen cloud.
• Draft a Kubernetes manifest and Dockerfile for a Python agent (long‑running and per‑job variants).
• Suggest sizing guidelines (CPU, memory, bandwidth) based on expected concurrent streams.
Which of the three follow‑ups above would you like next, and which cloud/ingress are you using?
Sources:
Distributed Setup | LiveKit docs |
Deploy to Kubernetes | LiveKit docs |
An open source stack for real-time multimodal AI |
examples/drive-thru | livekit/livekit_composite | DeepWiki |
Deploying LiveKit | LiveKit docs