if anyone has experience in self hosting livekit t...
# self-hosting
p
if anyone has experience in self hosting livekit to google GKE i might need some help with it
n
Hi @prehistoric-printer-73777 What is the issue you're facing in GKE? I can recommend my blog, it is using AWS EKS, but everything should be essentially the same outside of the LoadBalancer service annotation. We're using LiveKit the same way in GKE for years with no issue. You actually don't any special annotation in GKE the LoadBalancer will work fine, but it does not support multiprotocol service (a service with both TCP and UDP ports) so you might need two different gatewaya for TURN-UDP and TURN-TCP. https://medium.com/l7mp-technologies/deploying-webrtc-applications-in-aws-eks-a-step-by-step-guide-with-livekit-and-stunner-c94309af4ed8
c
@narrow-cricket-87449 I’m trying out your guide for AWS right now. Can you share any tips on how I can connect an external phone system to the livekit setup using SIP with your setup?
n
Yeah, kind of :D So create a regular SIP server deployment, but limit the port range to only 49 ports, so example use range 30000 - 30048 And the create a LoadBalancer service for it using NLB where you expose the SIP signalling port (5060) and you have also explicitly list all the RTP ports from 30000 to 30048 one by one. You also have to set the NAT_1_TO_1_IP env to the public IP of the LoadBalancer address you got there, and turn off the public IP detection. That way no matter which port the signalling chose for the RTP traffic it will be forwarded to the SIP server. But there huge limitations: • You can only run 1 replica at a time, since multiple of them will scrue up the LoadBalancing • You can only handle 49 parallel calls at the same time (this is an NLB limitation that you can only definien max 50 listeners, you need one port for the signalling traffic, so you left with 49 ports for the RTP. You cannot define port ranges, you have to explicitly list all 49 port in the range)
c
And the create a LoadBalancer service for it using NLB where you expose the SIP signalling port (5060) and you have also explicitly list all the RTP ports from 30000 to 30048 one by one.
How do I do this? Via annotations? Do you have an example? also for the
NAT_1_TO_1_IP
where’s that options? 😁 I’m okay with the limitations as a start
Something like this in the config of the SIP server:
Copy code
nat_1_to_1_ip: IP or DNS from cluster?
use_external_ip: false
rtc:
  port_range_start: 30000
  port_range_end: 30010
n
yes, exactly
I'm not sure wheter the SIP server supports DNS in the nat_1_to_1_ip, so I use raw IP there
c
Is the Raw IP from the stunner loadbalancer?
n
no no, the service you create for the SIP server
something like this:
Copy code
apiVersion: v1
kind: Service
metadata:
  name: livekit-sip-nlb
  namespace: livekit
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-type: "nlb"
    service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing"
    service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
    service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: "true"
    service.beta.kubernetes.io/aws-load-balancer-target-group-attributes: stickiness.enabled=true,stickiness.type=source_ip
spec:
  type: LoadBalancer
  ports:
    - name: sip-udp
      port: 5060
      targetPort: 5060
      protocol: UDP
    # RTP ports 30000-30048
    - name: rtp-port-30000
      port: 30000
      targetPort: 30000
      protocol: UDP
    - name: rtp-port-30001
      port: 30001
      targetPort: 30001
      protocol: UDP
    - name: rtp-port-30002
      port: 30002
      targetPort: 30002
      protocol: UDP
... to port 30048
c
Trying it out immediately
I’m stilling failing with something but I’m not sure it’s Stunner specific
Copy code
```{
  "level": "warn",
  "ts": 1755804577.7767947,
  "logger": "sip",
  "caller": "sip/inbound.go:302",
  "msg": "Rejecting inbound, auth check failed",
  "nodeID": "NE_SiETZ4gXMTDP",
  "callID": "SCL_qQLEzuPJQKmw",
  "fromIP": "XX.XX.XX.248",
  "toIP": "hostXXXX.elb.eu-west-1.amazonaws.com:5060",
  "fromHost": "52.212.66.56",
  "fromUser": "+45XXXXXX",
  "toHost": "hostXXXX.elb.eu-west-1.amazonaws.com",
  "toUser": "+4578XXXXX",
  "sipTag": "58A5q30",
  "sipCallID": "b493f5d7-7601-494a-a82f-e3dfc187eb60",
  "error": "no response from servers"
}
n
Well STUNner does not participate in the SIP traffic at all, so it has nothing to do with this This is due to the fact that SIP does not support ICE so you cannot use STUN / TURN to handle NAT, you must somehow force a direct connection
But based on the logs, it seems to me that you have connection, just the credentials are not set up well
Do You have SIP inbound trunk and dispatch rule setup?
c
Yeah there’s some kind of connection. This is the sip configs:
Copy code
{
  "dispatch_rule": {
    "rule": {
      "dispatchRuleIndividual": {
        "roomPrefix": "call-"
      }
    },
    "name": "Geneys"
  }
}
{
  "trunk": {
    "name": "Geneys",
    "numbers": [
      "+45XXXXXX"
    ]
  }
}
n
Should you set the Trunk ID in the dispatch rule?
c
Same result. Default should match any trunk
Can I do anything in the “toHost” and “toIP” perhaps?
n
I'm not sure, I don't really use these options...
The toIP field is also a bit wierd, given it has a port number
c
The
"error": "no response from servers"
is what sticks out to me though
n
Can you send the SIP config yaml?
What did you used in the nat_1_to_1_ip?
c
Copy code
logging:
  level: debug
  json: true
redis:
  cluster_addresses:
    - 'dev-redis-0001-001.amazonaws.com:6379'
    - 'dev-redis-0001-002.amazonaws.com:6379'
  username: 'livekit'
  password: 'XXXXXX'
  tls:
    enabled: true
nat_1_to_1_ip: '10.99.ZZZ.ZZ'
use_external_ip: false
rtp_port: 30000-30003
n
Also which SIP provider are you trying to use?
10.99.xx.xx? Is that a private address? :D
c
Genesys
Should be a public IP
n
It should be a public IP, one the the LoadBalancer hostname translates to
c
Copy code
nslookup 10.99.18X.XX
Server:		10.10.0.2
Address:	10.10.0.2#53

Non-authoritative answer:
94.181.XX.XX.in-addr.arpa	name = ip-10-XXXXXx.eu-west-1.compute.internal.
p
@narrow-cricket-87449 so only 48 parallels calls? then what's the point of using Kubernetes if it's not scalable?
c
@narrow-cricket-87449 I managed to get the SIP connection to go through and my livekit room is created and my agent joins. However, the sounds to the room over the SIP channel doesn’t work - i.e. the AI can’t hear me - any tips?
Should the NAT_1_TO_1 IP be the Stunner IP or the SIP server?
n
The SIP server (STUNner does not participate in the SIP calls at all)
c
Roger. Also what I have now
n
I'm wondering whether you truly have dataplane (RTP) connection then
Does the SIP server log indicate any error?
c
It does a few warnings with
"SIP request handler not found
But nothing sticks out
Is it
nat_1_to_1_ip
or
media_nat_1_to_1_ip
?
n
Do you have a I'm using just nat_1_to_1_ip
Do you have a way to enter into a LiveKit room?
E.g. with LiveKit meet or something?
You could check there whether the room indeed does not get the audio from the SIP call
c
Yes. Connection test works and I can use meet.livekit.io
n
Did you already checked this? Meaning that you enter the room with Meet where the call is?
c
The call ends up in a livekit room and my AI agent responds in there
My audio is just not sent to the room
n
But if you in the same room with LiveKit Meet, and you talk, the AI agent talks back?
c
Yes
n
Hmmm
Interesting
I'm not sure what could cause this
I would say that maybe the actual voice connection does not build up, but sonce last there's no error oj the SIP server I'm not sure
Does the call terminate after a while, or just when you hang up?
c
Fails after like 10-15 seconds with
media timeout
I can see now. Status 486
n
So I believe something is not okay with the RTP connection
The one going to the random UDP port from the pool 30000 - 300something
c
I see. I noticed this setting in Twilio: Symmetric RTP Disabled Twilio will send RTP to the destination negotiated in the SDP. This setting is considered to be more secure and therefore recommended
n
This is on LiveKit docs?
c
Oh man! That worked!!
n
Nice
c
Wow man - you’ve been a star
❤️ 1
This was amazing. I love open source. I’ll let you know what I’ve built - it’s for some awesome use case ❤️
n
Cool
Let me know if you want a quick video chat, happy to talk to you that way as well ;)
c
I have to run now - but I’ll take you up on that
✅ 1
n
@prehistoric-printer-73777 back to your question: So this 48 call limit is a complex one. The main issue is the SIP (and actually Webrtc as well) has such a weird networking modell, which is usually not conformant with the "modern" cloud / load balancerer based networking. Kubernetes itself was mostly build for stateless http based workloads, anything UDP based has a generally way less solution there. webRTC at least supports ICE, meaning you can use STUN and TURN to overcome some NAT problems, that is why we built STUNner to solve this problem. But SIP does not support ICE, so you have to somehow make a direct connection to a random UDP port. Well here comes the LoadBalancer limitations in cloud providers (which is also not a Kubernetes limitation): AWS can have max 50 ports, GCP 100, Azure max 300 (as far as I know). Oracle support L3 LoadBalancer which does not touch L4 port, so there's no such limit there.
If You have more parallel calls then 50 / 100, you have a giant call center service, so you still can run LiveKit SIP on a simple VM (not behind a LoadBalancer) or use some olds school SIP magic with Kamailo or something, but that is beyond my knowledge and generally very few engineers work with these olds school SIP stuff these days.