⚠️ These instructions may no longer be validUnfortunately, I began having several connectivity issues with my LiveKit cluster on Fly. I have since migrated off of the service and no longer maintain these instructions.
This guide is still available in case it proves helpful to anyone else, but you may have difficulty hosting a LiveKit server or cluster using these steps.
LiveKit is an open source platform for real-time communication (WebRTC) based on the Pion Go WebRTC stack. This example allows you to easily run a single-node LiveKit server on Fly.io hosting. This can be used to run a personal server for my LiveKit AVClient Module for FoundryVTT.
To provide a better reconnection mechanism with LiveKit, redis is also deployed to Fly. The redis steps can optionally be skipped, however users may not automatically reconnect if there is an interruption to the WebSocket connection during a session.
Note that this implementation does not allow you to scale to multiple LiveKit servers due to Fly only providing a single BGP Anycast ipv4 address per application. There are ways to accomplish this with Fly, but it is not the topic of this example.
A functioning Docker installation on the machine you will be deploying from.
- Follow Fly's QuickStart guide: Installing flyctl
- Follow Fly's QuickStart guide: Login to Fly
- Switch to the redis folder and review the configuration files. No changes should be needed.
- Init a new Fly app for redis
flyctl apps create
- Create an app name, or let one be auto-generated. Remember this name for later steps, indicated with <REDIS_APP_NAME>
- Determine your primary region, listed as Region Pool. Remember this for later steps, indicated with <REGION>
flyctl -a <REDIS_APP_NAME> regions list
- Create a persistent volume for your redis app
flyctl -a <REDIS_APP_NAME> volumes create livekit_redis --region <REGION>
- Add a secure password as an application secret to secure redis. I recommend randomly generating a string for this. Remember this for later steps, indicated with <YOUR_REDIS_PASSWORD>
flyctl -a <REDIS_APP_NAME> secrets set REDIS_PASSWORD=<YOUR_REDIS_PASSWORD>
- Deploy the redis app from from the redis path
flyctl -a <REDIS_APP_NAME> deploy
- Switch to the livekit folder and review the configuration files. No changes should be needed.
- Init a new fly app for LiveKit
flyctl apps create
- Create an app name, or let one be auto-generated. Remember this name for later steps, indicated with <LIVEKIT_APP_NAME>
- Set the region to match your redis app
flyctl -a <LIVEKIT_APP_NAME> regions set <REGION>
- Generate an API key/secret pair (for more information, see LiveKit's guide: Generate API key and secret)
docker run --rm livekit/livekit-server generate-keys
- Note the generated key/secret pair for use in later steps, indicated with <API_KEY> and <SECRET_KEY>
- Add the LiveKit key/secret pair as an application secret on LiveKit
flyctl -a <LIVEKIT_APP_NAME> secrets set LIVEKIT_KEYS="<API_KEY>: <SECRET_KEY>"
- Add the redis host as an application secret on LiveKit
flyctl -a <LIVEKIT_APP_NAME> secrets set REDIS_HOST=<REDIS_APP_NAME>.internal:6379
- Add the redis password as an application secret on LiveKit
flyctl -a <LIVEKIT_APP_NAME> secrets set REDIS_PASSWORD=<YOUR_REDIS_PASSWORD>
- Deploy the LiveKit app from the livekit path
flyctl -a <LIVEKIT_APP_NAME> deploy
- Congratulations! LiveKit is now running at
<LIVEKIT_APP_NAME>.fly.dev
with yor API key/secret pair. Note that since we are using the Fly load balancer, which provides SSL termination, the sever is running under secure websockets (wss:https://
) on port443
From here, you can continue to configure the app however you would like. For example, you can add a custom domain by following Fly's documentation Custom Domains for SaaS.