livekit / livekit-helm

LiveKit Helm charts
https://docs.livekit.io
Apache License 2.0
50 stars 59 forks source link

feat: Google NEG annotations for GCLB #69

Closed arrase closed 1 year ago

arrase commented 1 year ago

Allow Google Cloud Load Balancing instead of kubernetes ingress. Enables NEG annotations to configure region load balancing with google cloud, also you can setup livekit under a subpath of your domain.

By example we are using this to deploy two copies of livekit , one as main service and the other one as backup under wss://my-domain.com/livekit/main and wss://my-domain.com/livekit/backup

Here is a terraform example:

resource "google_compute_health_check" "http-health-check" {
  name        = "${local.website_domain_name_dashed}-http-health-check"
  description = "Health check via http"

  timeout_sec         = 1
  check_interval_sec  = 1
  healthy_threshold   = 4
  unhealthy_threshold = 5

  http_health_check {
    request_path       = "/"
    port_specification = "USE_SERVING_PORT"
  }
}

data "google_compute_network_endpoint_group" "livekit" {
  name = var.livekit_neg
  zone = var.zone
}

resource "google_compute_backend_service" "livekit" {
  name          = "${local.website_domain_name_dashed}-backend-service-livekit"
  health_checks = [google_compute_health_check.http-health-check.id]
  timeout_sec   = var.livekit_gclb_timeout_sec

  backend {
    balancing_mode = "RATE"
    max_rate       = 1000
    group          = data.google_compute_network_endpoint_group.livekit.id
  }
}

resource "google_compute_url_map" "urlmap" {
  provider = google-beta
  project  = var.project

  name        = "${local.website_domain_name_dashed}-url-map"
  description = "URL map for ${local.website_domain_name_dashed}"

  default_service = google_compute_backend_bucket.root.self_link

  host_rule {
    hosts        = [var.website_domain_name, "www.${var.website_domain_name}"]
    path_matcher = "all-paths"
  }

  path_matcher {
    name            = "all-paths"
    default_service = google_compute_backend_bucket.root.self_link

    path_rule {
      paths   = ["/livekit/main", "/livekit/main/*"]
      service = google_compute_backend_service.livekit.self_link
      route_action {
        url_rewrite {
          path_prefix_rewrite = "/"
        }
      }
    }

    path_rule {
      paths   = ["/*"]
      service = google_compute_backend_bucket.root.self_link
    }
  }
}
davidzhao commented 1 year ago

I'm not too familiar with this option but it seems rather specific to GCP. It does look a bit different in terms of bypassing Ingress alltogether.

In order for this to be useful to others, could you add a bit of docs in server-sample? This could help others to understand how this option could be used in practice.

arrase commented 1 year ago

There is not too much to set up at livekit side, i added a sample file