Call a SIP echo service in Kubernetes๐
Warning
The SIP gateway is in beta: the API may change in any release and there is no support on any tier. Certain features require premium support: see here for the limits and pricing.
This tutorial connects a SIP phone on your machine through a STUNner SIP Gateway to a SIP echo
service running in Kubernetes: STUNner proxies the SIP signaling and relays the RTP media, the
echo service answers the call and sends the media back, and mediactl counts what comes
back. It is the smallest end-to-end test of the beta SIP gateway, the
same path a carrier's calls take into your SIP server.
In this tutorial you will learn how to:
* deploy a SIP service into Kubernetes,
* make a STUNner Gateway a SIP gateway with a SIPTrunk,
* call the service through STUNner with the mediactl tool.
Prerequisites๐
- A STUNner installation from the official Helm chart, see the installation guide.
- A load balancer that preserves the source address of the traffic it forwards
(
externalTrafficPolicy: Local): the managed load balancers of the large cloud providers do, and so does MetalLB on a local kind cluster. - A host to run
mediactlon whose address the cluster sees unchanged: a machine with a public IP address, or your own machine calling a local kind cluster. STUNner matches the media of a call to the address in its SDP, so a phone behind a NAT that rewrites its source address gets no media back (carriers do not sit behind such NATs, which is why STUNner can rely on this). - The
mediactltool, a media source and sink that also makes SIP calls: download it from the STUNner releases or install it withgo install github.com/l7mp/stunner/v2/cmd/mediactl@latest. envsubstfrom GNU gettext, which fills your address into the manifests: installed on most Linux systems (gettext-baseon Debian and Ubuntu,gettexton macOS with Homebrew).
Configuration๐
- Deploy the SIP echo service: the STUNner
mediactlimage, answering every call on UDP port 5060 and echoing the media.
cd stunner
kubectl apply -f docs/examples/sip-echo/sip-echo-server.yaml
- Find the address your calls come from, as the cluster sees it: on a local kind cluster this
is the address of your machine on the kind network (
docker network inspect kind), otherwise your public address (for instancecurl -4 ifconfig.me).
export MY_IP=$(curl -s -4 ifconfig.me)
- Create the SIP Gateway. The manifest holds the GatewayClass and the GatewayConfig of the other
tutorials, a Gateway with a SIP listener on UDP port 5060 and a media listener on UDP port
30000, a SIPTrunk that admits calls only from your address, and a UDPRoute to the echo service.
The Gateway names the SIPTrunk in
spec.infrastructure.parametersRef, which makes it a SIP gateway; thestunner.l7mp.io/external-traffic-policy: localannotation keeps the source addresses intact.
kubectl create namespace stunner
envsubst '$MY_IP' < docs/examples/sip-echo/sip-echo-stunner.yaml | kubectl apply -f -
- Check that the Gateway is programmed and has a public address.
kubectl -n stunner get gateway sip-gateway
The PROGRAMMED column should read True and ADDRESS should hold the load balancer address.
A Gateway that is not accepted says why in its status: kubectl -n stunner get gateway
sip-gateway -o yaml.
Test๐
Call the echo service for ten seconds, letting mediactl find the address of the Gateway through
your kubeconfig, and rate the call as a voice call:
mediactl sip call -t 10s --voip k8s://stunner/sip-gateway/sip
Without a kubeconfig, call the address of the Gateway: mediactl sip call -t 10s
sip:echo@<address>:5060. Start mediactl: it sends G.711-sized audio packets for ten seconds,
logs every second, and terminates with a summary:
...
mediactl INFO: summary ..., lost 0/496 (0.00%), rtt min/avg/max 280ยตs/466ยตs/907ยตs, jitter 29ยตs, R-factor 93.0, MOS 4.40
No loss means the media made the round trip through STUNner. The loss, the round trip and the
jitter are the numbers VoIP quality is judged by, and --voip rates them with the ITU-T E-model as
a G.711 call: an R-factor above 80 and a MOS above 4 mean a good call, 4.4 is as good as G.711
gets. You can watch the call in the STUNner dataplane, while it runs:
stunnerctl -n stunner status sip-gateway
If in trouble, try the below:
- The call gets no answer. The SIP listener admits only the addresses of
allowedSources. Check thatMY_IPis the address the cluster sees, and that the load balancer preserves it (thestunner.l7mp.io/external-traffic-policy: localannotation). - The call connects but
receivedstays zero. The media is matched to the address in the SDP ofmediactl: a NAT on the way that rewrites the source address breaks the match. Runmediactlfrom a machine with a public address, or from the network of a local kind cluster. - The Gateway is not accepted. The open-source operator supports no SIPTrunk: install the official STUNner chart. Each tier serves a limited number of SIP Gateways (see the pricing); the oldest ones by creation time win.
Kernel offload๐
In production the dataplane shares its node with busy neighbors, and a traffic spike can leave it
short of CPU. Model this: give the Gateway a Dataplane of its own, squeezed to 20m CPU, and place
ten calls at once. Note that the new Dataplane replaces the Gateway's pod: wait until kubectl -n
stunner get pods shows a single pod before calling.
kubectl apply -f docs/examples/sip-echo/sip-echo-dataplane.yaml
kubectl -n stunner patch gatewayconfig stunner-gatewayconfig --type merge -p '{"spec":{"dataplane":"sip-echo"}}'
mediactl sip call -P 10 -t 15s --voip k8s://stunner/sip-gateway/sip
...
mediactl INFO: total of 10 streams: ..., lost 5.9k/7.2k (82.16%), ..., MOS 1.00
The calls are unusable: the media waits in user space for the CPU. The kernel offload of STUNner relays the media in the Linux kernel instead, which required much less CPU. Switch it on: the same pod with the same 20m CPU, no restart, and the calls are as again at the maximum quality G.711 can provide.
kubectl patch dataplane sip-echo --type merge -p '{"spec":{"offloadEngine":"TC"}}'
mediactl sip call -P 10 -t 15s --voip k8s://stunner/sip-gateway/sip
...
mediactl INFO: total of 10 streams: ..., lost 0/7k (0.00%), ..., MOS 4.40
The free tier offloads a limited number of flows per dataplane pod. A STUNner license offloads many more and unlocks the premium features: see the pricing and the premium installation guide.
Clean up๐
kubectl delete -f docs/examples/sip-echo/sip-echo-server.yaml
envsubst '$MY_IP' < docs/examples/sip-echo/sip-echo-stunner.yaml | kubectl delete -f -
kubectl delete -f docs/examples/sip-echo/sip-echo-dataplane.yaml --ignore-not-found
kubectl delete namespace stunner