Skip to content

An example on how to deploy LiveKit on Fly.io

License

Notifications You must be signed in to change notification settings

adorack/livekit-flydotio

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Install and configure a single-node LiveKit server on Fly.io

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.

Prerequisites

A functioning Docker installation on the machine you will be deploying from.

Install and configure flyctl

  1. Follow Fly's QuickStart guide: Installing flyctl
  2. Follow Fly's QuickStart guide: Login to Fly

Launch redis on Fly

  1. Switch to the redis folder and review the configuration files. No changes should be needed.
  2. Init a new Fly app for redis
    flyctl apps create
  3. Create an app name, or let one be auto-generated. Remember this name for later steps, indicated with <REDIS_APP_NAME>
  4. Determine your primary region, listed as Region Pool. Remember this for later steps, indicated with <REGION>
    flyctl -a <REDIS_APP_NAME> regions list
  5. Create a persistent volume for your redis app
    flyctl -a <REDIS_APP_NAME> volumes create livekit_redis --region <REGION>
  6. 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>
  7. Deploy the redis app from from the redis path
    flyctl -a <REDIS_APP_NAME> deploy

Launch LiveKit on Fly

  1. Switch to the livekit folder and review the configuration files. No changes should be needed.
  2. Init a new fly app for LiveKit
    flyctl apps create
  3. Create an app name, or let one be auto-generated. Remember this name for later steps, indicated with <LIVEKIT_APP_NAME>
  4. Set the region to match your redis app
    flyctl -a <LIVEKIT_APP_NAME> regions set <REGION>
  5. 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
  6. Note the generated key/secret pair for use in later steps, indicated with <API_KEY> and <SECRET_KEY>
  7. 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>"
  8. Add the redis host as an application secret on LiveKit
    flyctl -a <LIVEKIT_APP_NAME> secrets set REDIS_HOST=<REDIS_APP_NAME>.internal:6379
  9. Add the redis password as an application secret on LiveKit
    flyctl -a <LIVEKIT_APP_NAME> secrets set REDIS_PASSWORD=<YOUR_REDIS_PASSWORD>
  10. Deploy the LiveKit app from the livekit path
    flyctl -a <LIVEKIT_APP_NAME> deploy
  11. 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://) on port 443

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.

Support my work

Become a Patron Donate via Ko-Fi

About

An example on how to deploy LiveKit on Fly.io

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dockerfile 50.8%
  • Shell 49.2%