Hey all! I am trying to self-host LiveKit using S...
# self-hosting
g
Hey all! I am trying to self-host LiveKit using STUNner in Kubernetes, but I'm running into two problems: 1. I sometimes get a peer connection timeout when trying to connect via the UI (like 50% of the time) 2. When rejoining with the same user and the same token (that hasn't expired yet), the agent doesn't reply, when it previously did (this is rarer, the previous is more common) It seems that when I use a new user when creating the auth token with the
lk
CLI and waiting a while, this usually solves the problem, though sometimes it still comes up here and there. Any ideas what may be going wrong? I linked logs from my LiveKit server deployment in Kubernetes as well as my voice agent deployment in Kubernetes, if those might be helpful.
I noticed that there is some sort of job that gets kicked off (from reading the livekit-server logs) that takes around 20 seconds to complete, and if a request is made during that time, it fails.
n
Hi @great-hospital-63736 I'm a member of the STUNner team. Any chance you can share also the STUNner logs, and also some info on where are you hosting you environment?
Also: is this agent the basic voice agent example or something different that you cutomly built?
g
I followed the guide here, but I used a different domain (as I use istio internally)
I am hosting the environment in GKE
This is a basic voice agent
@narrow-cricket-87449 for which service are you looking for the logs?
n
I'm mostly interested in the STUNnerd logs (which belongs to the actual TURN gateway, not the operator)
what does Istio do in your env?
does this mean that you use a Gateway for exposing the HTTP(S) service, not an Ingress right?
do you think I does something with the internal routing as well?
what you have to understand that the communicaiton between STUNner <---> LiveKit server and LiveKit Server <---> AI Agent is both RTP over UDP which uses basically a random port number if Istio for reason blocks it, or does some wierd stuff via the Envoy sidecars, it can easily break these connections
generally the whole Envoy / Istion (Service Mesh in general) is very bad with UDP, and I have to admint I don't really have any experience with using them for LiveKit
the LiveKit Helm chart by default will have an annotation for e.g. to disable Istio sidecar injection
these annotations are also in our examples as well for the LiveKit server only
maybe the solution is something like add this same annotation (to disable istio sidecar injection) for both STUNner and the AI Agent
g
I do use an ingress, which points to the livekit host with this information:
Copy code
rules:
  - host: livekit.<domain>
    http:
      paths:
        - backend:
            service:
              name: istio-ingress
              port:
                number: 443
          path: /*
          pathType: ImplementationSpecific
          
  - host: livekit-client.<domain>
    http:
      paths:
        - backend:
            service:
              name: istio-ingress
              port:
                number: 443
          path: /*
          pathType: ImplementationSpecific
and then forwards to the right service with the virtual service:
Copy code
spec:
  gateways:
    - istio-ingress/webapp-gateway
  hosts:
    - livekit.<domain>
    - livekit-client.<domain>
  http:
    - match:
        - headers:
            host:
              exact: livekit-client.<domain>
      route:
        - destination:
            host: lk-react.default.svc.cluster.local
            port:
              number: 3000
    - match:
        - headers:
            host:
              exact: livekit.<domain>
      route:
        - destination:
            host: livekit-server.default.svc.cluster.local
            port:
              number: 7880
Also, without the agent involved, I am getting this error
When connecting to a livekit room, I sometimes ONLY see this log:
selected node for room
, upon which the connections fails with a PeerConnection Timeout. But, when I waited a little and tried again, I got the expected
starting RTC session
log after the
selected node for room
one, which is expected. Explain in the code with code pointers why we may or may not see the
starting RTC session
log:
```2025-09-03T184752.308001034Z 2025-09-03T184752.307Z INFO livekit service/roomallocator.go:166 selected node for room {"room": "room", "selectedNodeID": "ND_GfSccG8igzua"} │
│ 2025-09-03T184855.569056427Z 2025-09-03T184855.568Z INFO livekit service/roomallocator.go:166 selected node for room {"room": "room", "selectedNodeID": "ND_CVxSwq4zq6De"} │
│ 2025-09-03T184855.573279799Z 2025-09-03T184855.573Z INFO livekit service/roommanager.go:394 starting RTC session {"room": "room", "roomID": "RM_8wjANyUsqyZ3", "participant": "money-3", "pID": "PA_VorVa6NZFv6X", "remote": false, "roo │
│ m": "room", "nodeID": "ND_CVxSwq4zq6De", "numParticipants": 0, "participantInit": {"Identity": "money-3", "Reconnect": false, "ReconnectReason": "RR_UNKNOWN", "AutoSubscribe": true, "Client": {"sdk": "JS", "version": "1.3.0", "protocol": 8, "os": "Mac │
│ OS X", "osVersion": "10.15.7", "deviceModel": "Mac", "browser": "Chrome", "browserVersion": "139.0.0"}, "Grants": {"Identity": "", "Kind": "", "Video": {"RoomCreate": false, "RoomList": false, "RoomRecord": false, "RoomAdmin": false, "RoomJoin": true │
│ , "Room": "room", "CanPublish": "not-set", "CanSubscribe": "not-set", "CanPublishData": "not-set", "CanPublishSources": [], "CanUpdateOwnMetadata": "not-set", "IngressAdmin": false, "Hidden": false, "Recorder": false, "Agent": false, "CanSubscribeMetr │
│ ics": "not-set", "DestinationRoom": ""}, "SIP": {}, "RoomConfig": {}, "RoomPreset": ""}, "Region": "", "AdaptiveStream": true, "ID": "", "SubscriberAllowPause": "not-set", "DisableICELite": false, "CreateRoom": {"name": "room"}}}```
@narrow-cricket-87449 let me know if it easier to set up a quick chat!
Very much appreciate the help
n
Hi @great-hospital-63736 Sorry, from this logs I cannot really see what could cause this issue. I can offer a quick direct help some time, we could probably figure this out faster that way I'm in Europe / Budapest timezone, however today won't work for me, only early next week
g
Hey! I think I largely figured out one problem, which was that I had a separate livekit cluster in a different GKE that was intercepting requests. I am still running into the issue where if I connect <20 seconds after the last user session ended, then the agent doesn't rejoin. I believe it takes 20 seconds for the agent to leave the room when the session is ended, so if you join before this job can finish, the agent doesn't respond. I attached some logs for the successful/failing case. If you have ideas here, I'd love to set up a time Thursday or Friday if that works for you!