Karl uses a JSON configuration file with sensible defaults. All settings can be overridden via environment variables.
- Configuration File Location
- Complete Configuration Example
- Configuration Sections
- Environment Variables
Karl looks for configuration in the following order:
- Path specified via
-configflag:./karl -config /path/to/config.json - Path specified via
KARL_CONFIG_PATHenvironment variable - Default:
./config/config.json
Karl monitors the configuration file for changes and automatically reloads certain settings without requiring a restart.
Settings that apply immediately:
- WebRTC settings (STUN/TURN servers, recording path)
- Recording settings (retention, format)
- Alert thresholds
- Integration settings (SIP proxy registration)
- RTP quality settings (applied to new sessions)
Settings that require a restart:
- Transport settings (UDP/TCP/TLS ports and listeners)
- NG protocol port
- Session port ranges
- Database connection settings
When configuration changes are detected, Karl logs the applied changes. Check the logs to verify updates took effect.
{
"version": "1.0.0",
"environment": "production",
"transport": {
"udp_enabled": true,
"udp_port": 12000,
"tcp_enabled": false,
"tcp_port": 12001,
"tls_enabled": false,
"tls_port": 12002,
"tls_cert": "/etc/karl/certs/server.crt",
"tls_key": "/etc/karl/certs/server.key",
"ipv6_enabled": false,
"mtu": 1500
},
"ng_protocol": {
"enabled": true,
"socket_path": "/var/run/karl/karl.sock",
"udp_port": 22222,
"timeout": 30
},
"sessions": {
"max_sessions": 10000,
"session_ttl": 3600,
"cleanup_interval": 60,
"min_port": 30000,
"max_port": 40000
},
"jitter_buffer": {
"enabled": true,
"min_delay": 20,
"max_delay": 200,
"target_delay": 50,
"adaptive_mode": true,
"max_size": 100
},
"rtcp": {
"enabled": true,
"interval": 5,
"reduced_size": false,
"mux_enabled": true
},
"fec": {
"enabled": true,
"block_size": 48,
"redundancy": 0.30,
"adaptive_mode": true,
"max_redundancy": 0.50,
"min_redundancy": 0.10
},
"recording": {
"enabled": true,
"base_path": "/var/lib/karl/recordings",
"format": "wav",
"mode": "stereo",
"sample_rate": 8000,
"bits_per_sample": 16,
"max_file_size": 104857600,
"retention_days": 30
},
"api": {
"enabled": true,
"address": ":8080",
"auth_enabled": false,
"rate_limit_per_min": 60,
"cors_enabled": false,
"cors_origins": "*",
"tls_enabled": false,
"tls_cert": "",
"tls_key": ""
},
"webrtc": {
"enabled": true,
"webrtc_port": 8443,
"stun_servers": [
"stun:stun.l.google.com:19302",
"stun:stun1.l.google.com:19302"
],
"turn_servers": [],
"max_bitrate": 2000000,
"start_bitrate": 1000000,
"bw_estimation": true,
"tcc_enabled": true
},
"integration": {
"opensips_ip": "",
"opensips_port": 0,
"kamailio_ip": "",
"kamailio_port": 0,
"media_ip": "auto",
"public_ip": "",
"keepalive_interval": 30,
"interfaces": {
"internal": {
"name": "internal",
"address": "10.0.0.5",
"advertise_addr": "10.0.0.5"
},
"external": {
"name": "external",
"address": "10.0.0.5",
"advertise_addr": "198.51.100.10"
}
}
},
"database": {
"mysql_dsn": "",
"redis_enabled": false,
"redis_addr": "localhost:6379",
"redis_cleanup_interval": 3600,
"max_connections": 10,
"connection_timeout": 30
},
"srtp": {
"srtp_key": "",
"srtp_salt": ""
},
"alert_settings": {
"packet_loss_threshold": 0.05,
"jitter_threshold": 50.0,
"bandwidth_threshold": 1000000,
"notify_admin": false,
"admin_email": "",
"slack_webhook": ""
},
"hep": {
"hep_enabled": false,
"hep_server": "homer:9060",
"hep_capture_id": 1,
"hep_proto": "udp"
},
"cluster": {
"enabled": false,
"node_id": "karl-1",
"node_address": "10.0.0.5:22222",
"quorum_size": 2,
"replication_factor": 2,
"enable_fencing": false
}
}Controls the rtpengine-compatible NG protocol interface.
{
"ng_protocol": {
"enabled": true,
"socket_path": "/var/run/karl/karl.sock",
"udp_port": 22222,
"timeout": 30
}
}| Setting | Type | Default | Description |
|---|---|---|---|
enabled |
bool | true |
Enable NG protocol listener |
socket_path |
string | /var/run/karl/karl.sock |
Unix socket path for local communication |
udp_port |
int | 22222 |
UDP port for NG protocol |
timeout |
int | 30 |
Request timeout in seconds |
Controls session management and RTP port allocation.
{
"sessions": {
"max_sessions": 10000,
"session_ttl": 3600,
"cleanup_interval": 60,
"min_port": 30000,
"max_port": 40000
}
}| Setting | Type | Default | Description |
|---|---|---|---|
max_sessions |
int | 10000 |
Maximum concurrent sessions |
session_ttl |
int | 3600 |
Session time-to-live in seconds |
cleanup_interval |
int | 60 |
Interval for cleaning stale sessions (seconds) |
min_port |
int | 30000 |
Minimum RTP port number |
max_port |
int | 40000 |
Maximum RTP port number |
Port Range Calculation:
Each session requires 4 ports (RTP + RTCP for each direction). With the default range of 30000-40000:
- Available ports: 10,000
- Maximum sessions: 2,500
Adjust min_port and max_port based on your expected concurrent call volume.
Controls the adaptive jitter buffer for smooth audio playback.
{
"jitter_buffer": {
"enabled": true,
"min_delay": 20,
"max_delay": 200,
"target_delay": 50,
"adaptive_mode": true,
"max_size": 100
}
}| Setting | Type | Default | Description |
|---|---|---|---|
enabled |
bool | true |
Enable jitter buffer |
min_delay |
int | 20 |
Minimum buffering delay (ms) |
max_delay |
int | 200 |
Maximum buffering delay (ms) |
target_delay |
int | 50 |
Target delay for adaptive mode (ms) |
adaptive_mode |
bool | true |
Automatically adjust buffer size based on network conditions |
max_size |
int | 100 |
Maximum buffer size in packets |
Tuning Guide:
- Low latency networks:
min_delay: 10,target_delay: 30 - Standard networks:
min_delay: 20,target_delay: 50(default) - High jitter networks:
min_delay: 40,target_delay: 100
Controls RTCP (RTP Control Protocol) for quality monitoring.
{
"rtcp": {
"enabled": true,
"interval": 5,
"reduced_size": false,
"mux_enabled": true
}
}| Setting | Type | Default | Description |
|---|---|---|---|
enabled |
bool | true |
Enable RTCP processing |
interval |
int | 5 |
RTCP report interval in seconds |
reduced_size |
bool | false |
Use reduced-size RTCP (RFC 5506) |
mux_enabled |
bool | true |
Enable RTCP-mux (RTP and RTCP on same port) |
Controls FEC for packet loss recovery.
{
"fec": {
"enabled": true,
"block_size": 48,
"redundancy": 0.30,
"adaptive_mode": true,
"max_redundancy": 0.50,
"min_redundancy": 0.10
}
}| Setting | Type | Default | Description |
|---|---|---|---|
enabled |
bool | true |
Enable Forward Error Correction |
block_size |
int | 48 |
Number of packets per FEC block |
redundancy |
float | 0.30 |
Base redundancy ratio (0.0-1.0) |
adaptive_mode |
bool | true |
Adjust redundancy based on packet loss |
max_redundancy |
float | 0.50 |
Maximum redundancy when adapting |
min_redundancy |
float | 0.10 |
Minimum redundancy when adapting |
Redundancy Impact:
| Redundancy | Bandwidth Overhead | Recovery Capability |
|---|---|---|
| 0.10 (10%) | Low | Up to ~8% packet loss |
| 0.30 (30%) | Medium | Up to ~20% packet loss |
| 0.50 (50%) | High | Up to ~35% packet loss |
Controls call recording functionality.
{
"recording": {
"enabled": true,
"base_path": "/var/lib/karl/recordings",
"format": "wav",
"mode": "stereo",
"sample_rate": 8000,
"bits_per_sample": 16,
"max_file_size": 104857600,
"retention_days": 30
}
}| Setting | Type | Default | Description |
|---|---|---|---|
enabled |
bool | false |
Enable recording system |
base_path |
string | /var/lib/karl/recordings |
Directory for recording files |
format |
string | wav |
Output format: wav or pcm |
mode |
string | stereo |
Recording mode: mixed, stereo, or separate |
sample_rate |
int | 8000 |
Sample rate in Hz (8000, 16000, 48000) |
bits_per_sample |
int | 16 |
Bits per sample (8 or 16) |
max_file_size |
int | 104857600 |
Max file size before rotation (bytes) |
retention_days |
int | 30 |
Days to keep recordings before cleanup |
Recording Modes:
| Mode | Description | Files Created |
|---|---|---|
mixed |
Both parties mixed into mono | 1 file |
stereo |
Caller left channel, callee right | 1 file |
separate |
Each party in separate file | 2 files |
Storage Calculation:
WAV at 8kHz/16-bit: ~1 MB per minute per channel
- Mixed mode: ~1 MB/minute
- Stereo mode: ~2 MB/minute
- Separate mode: ~2 MB/minute (2 files)
Controls the REST API server.
{
"api": {
"enabled": true,
"address": ":8080",
"auth_enabled": false,
"rate_limit_per_min": 60,
"cors_enabled": false,
"cors_origins": "*",
"tls_enabled": false,
"tls_cert": "",
"tls_key": ""
}
}| Setting | Type | Default | Description |
|---|---|---|---|
enabled |
bool | true |
Enable REST API |
address |
string | :8080 |
Listen address and port |
auth_enabled |
bool | false |
Require API key authentication |
rate_limit_per_min |
int | 60 |
Max requests per minute per client |
cors_enabled |
bool | false |
Enable CORS headers |
cors_origins |
string | * |
Allowed CORS origins |
tls_enabled |
bool | false |
Enable HTTPS |
tls_cert |
string | Path to TLS certificate | |
tls_key |
string | Path to TLS private key |
Controls WebRTC functionality for browser-based clients.
{
"webrtc": {
"enabled": true,
"webrtc_port": 8443,
"stun_servers": [
"stun:stun.l.google.com:19302"
],
"turn_servers": [],
"max_bitrate": 2000000,
"start_bitrate": 1000000,
"bw_estimation": true,
"tcc_enabled": true
}
}| Setting | Type | Default | Description |
|---|---|---|---|
enabled |
bool | true |
Enable WebRTC support |
webrtc_port |
int | 8443 |
WebRTC signaling port |
stun_servers |
array | Google STUN | STUN servers for NAT traversal |
turn_servers |
array | [] |
TURN servers for relay |
max_bitrate |
int | 2000000 |
Maximum bitrate (bps) |
start_bitrate |
int | 1000000 |
Initial bitrate (bps) |
bw_estimation |
bool | true |
Enable bandwidth estimation |
tcc_enabled |
bool | true |
Enable Transport-CC feedback |
Controls integration with SIP proxies and network interface selection.
{
"integration": {
"opensips_ip": "",
"opensips_port": 0,
"kamailio_ip": "",
"kamailio_port": 0,
"media_ip": "10.0.0.5",
"public_ip": "198.51.100.10",
"keepalive_interval": 30,
"interfaces": {
"internal": {
"name": "internal",
"address": "10.0.0.5",
"advertise_addr": "10.0.0.5"
},
"external": {
"name": "external",
"address": "10.0.0.5",
"advertise_addr": "198.51.100.10"
}
}
}
}| Setting | Type | Default | Description |
|---|---|---|---|
opensips_ip |
string | OpenSIPS server IP for registration | |
opensips_port |
int | OpenSIPS server port | |
kamailio_ip |
string | Kamailio server IP for registration | |
kamailio_port |
int | Kamailio server port | |
media_ip |
string | auto |
IP address for media socket binding. Use auto for detection |
public_ip |
string | Public IP for NAT scenarios (used in SDP when no per-interface advertise_addr is set) |
|
keepalive_interval |
int | 30 |
Keepalive interval to SIP proxies (seconds) |
interfaces |
map | Named network interfaces for direction-based media routing (see below) |
Named interfaces allow Karl to advertise different IPs in SDP depending on which direction a call is heading. This is essential when your media server has separate internal and external network paths (e.g., a private IP for your PBX and an Elastic IP for carriers).
Each interface entry has:
| Setting | Type | Description |
|---|---|---|
name |
string | Interface identifier (e.g., internal, external) |
address |
string | Local IP to bind sockets on |
advertise_addr |
string | IP to put in SDP c= line and stream info. If empty, falls back to address |
port |
int | Optional port override |
How direction selects the interface:
The SIP proxy sends a direction array in the NG protocol request (e.g., ["internal", "external"]). Karl uses this to pick the correct interface:
direction[0]= originating side ("from")direction[1]= terminating side ("to")
For the offer (caller-side SDP), Karl uses direction[0] to select the interface. For the answer (callee-side SDP), Karl uses direction[1]. The selected interface's advertise_addr goes into the SDP, while address is used for the actual socket binding.
Example — carriers get the public IP, internal endpoints get the private IP:
{
"integration": {
"media_ip": "10.0.0.5",
"interfaces": {
"internal": {
"address": "10.0.0.5",
"advertise_addr": "10.0.0.5"
},
"external": {
"address": "10.0.0.5",
"advertise_addr": "198.51.100.10"
}
}
}
}Then in your SIP proxy, for calls toward an external carrier:
rtpengine_manage("... direction=internal direction=external");
Karl will bind the socket on 10.0.0.5 but put 198.51.100.10 in the SDP for the carrier-facing leg.
If no interfaces are configured, Karl falls back to media_ip for binding and public_ip for SDP advertisement (or media_ip if public_ip is empty).
Controls database connections for CDR and session storage.
{
"database": {
"mysql_dsn": "",
"redis_enabled": false,
"redis_addr": "localhost:6379",
"redis_cleanup_interval": 3600,
"max_connections": 10,
"connection_timeout": 30
}
}| Setting | Type | Default | Description |
|---|---|---|---|
mysql_dsn |
string | MySQL connection string | |
redis_enabled |
bool | false |
Enable Redis for session caching |
redis_addr |
string | localhost:6379 |
Redis server address |
redis_cleanup_interval |
int | 3600 |
Redis cleanup interval (seconds) |
max_connections |
int | 10 |
Maximum database connections |
connection_timeout |
int | 30 |
Connection timeout (seconds) |
MySQL DSN Format:
user:password@tcp(host:port)/database?parseTime=true
Example:
karl:secretpassword@tcp(127.0.0.1:3306)/karl?parseTime=true
Controls SRTP encryption settings.
{
"srtp": {
"srtp_key": "",
"srtp_salt": ""
}
}| Setting | Type | Default | Description |
|---|---|---|---|
srtp_key |
string | Master key for SRTP (base64 encoded) | |
srtp_salt |
string | Master salt for SRTP (base64 encoded) |
Controls quality alerting thresholds.
{
"alert_settings": {
"packet_loss_threshold": 0.05,
"jitter_threshold": 50.0,
"bandwidth_threshold": 1000000,
"notify_admin": false,
"admin_email": "",
"slack_webhook": ""
}
}| Setting | Type | Default | Description |
|---|---|---|---|
packet_loss_threshold |
float | 0.05 |
Alert when packet loss exceeds 5% |
jitter_threshold |
float | 50.0 |
Alert when jitter exceeds 50ms |
bandwidth_threshold |
int | 1000000 |
Alert when bandwidth exceeds threshold |
notify_admin |
bool | false |
Send alert notifications |
admin_email |
string | Email for alerts | |
slack_webhook |
string | Slack webhook URL for alerts |
Controls the HEPv3 exporter for sending RTCP packets to a Homer capture server. RTCP packets forwarded between legs in the media relay are exported with the Call-ID as the correlation ID. SIP traffic is not captured by Karl — for a full capture, let the SIP proxy send SIP to Homer (e.g. via Kamailio/OpenSIPS).
The connection is lazily established on first send and re-established automatically after failures, so a Homer outage at startup does not disable capture until restart.
{
"hep": {
"hep_enabled": true,
"hep_server": "homer.example.com:9060",
"hep_capture_id": 1,
"hep_proto": "udp"
}
}| Setting | Type | Default | Description |
|---|---|---|---|
hep_enabled |
bool | false |
Enable HEP exporter |
hep_server |
string | Homer capture server address (host:port) | |
hep_capture_id |
int | 0 |
Capture agent ID sent in HEP packets |
hep_proto |
string | udp |
Transport protocol to Homer (udp or tcp) |
Controls graceful shutdown behaviour. On SIGTERM, Karl marks itself unhealthy
and rejects new offers, then drains active calls for up to drain_timeout_seconds
before terminating. Set drain_timeout_seconds shorter than the pod's
terminationGracePeriodSeconds; otherwise in-flight calls will be cut off.
{
"shutdown": {
"drain_timeout_seconds": 60
}
}| Setting | Type | Default | Description |
|---|---|---|---|
drain_timeout_seconds |
int | 30 |
Max time to wait for calls to drain before teardown |
Controls multi-node clustering with Redis-backed session failover, split-brain detection, and consistent hashing.
{
"cluster": {
"enabled": true,
"node_id": "karl-1",
"node_address": "10.0.0.5:22222",
"quorum_size": 2,
"replication_factor": 2,
"enable_fencing": true
}
}| Setting | Type | Default | Description |
|---|---|---|---|
enabled |
bool | false |
Enable clustering |
node_id |
string | Unique identifier for this node | |
node_address |
string | This node's address (reachable by other nodes) | |
quorum_size |
int | 2 |
Minimum nodes for quorum |
replication_factor |
int | 2 |
Session replication factor on the hash ring |
enable_fencing |
bool | false |
Enable node fencing on partition detection |
Prerequisites: Redis must be enabled in the database section. The cluster manager uses Redis for session storage, pub/sub coordination, heartbeats, and split-brain detection.
How failover works:
- Each node sends heartbeats to Redis every second
- If a node misses 3 heartbeats, it's marked as failed
- The split-brain detector checks quorum before allowing takeover
- Surviving nodes redistribute the failed node's sessions via consistent hashing
- Ports are re-allocated and media relays restarted on the new owner
All configuration options can be overridden via environment variables:
| Variable | Config Path | Description |
|---|---|---|
KARL_CONFIG_PATH |
- | Path to configuration file |
KARL_LOG_LEVEL |
- | Logging level (debug, info, warn, error) |
KARL_HEALTH_PORT |
- | Health check port (default: :8086) |
KARL_METRICS_PORT |
- | Prometheus metrics port (default: :9091) |
KARL_API_PORT |
api.address |
REST API port |
KARL_NG_PORT |
ng_protocol.udp_port |
NG protocol UDP port |
KARL_RTP_MIN_PORT |
sessions.min_port |
Minimum RTP port |
KARL_RTP_MAX_PORT |
sessions.max_port |
Maximum RTP port |
KARL_MAX_SESSIONS |
sessions.max_sessions |
Maximum concurrent sessions |
KARL_RECORDING_PATH |
recording.base_path |
Recording storage path |
KARL_RECORDING_ENABLED |
recording.enabled |
Enable recording |
KARL_MYSQL_DSN |
database.mysql_dsn |
MySQL connection string |
KARL_REDIS_ENABLED |
database.redis_enabled |
Enable Redis |
KARL_REDIS_ADDR |
database.redis_addr |
Redis address |
KARL_MEDIA_IP |
integration.media_ip |
Media IP address |
KARL_PUBLIC_IP |
integration.public_ip |
Public IP address |
KARL_RUN_DIR |
- | Runtime directory |
Environment variables take precedence over configuration file values.