how can i configure prometheus adapter to enable l...
# ask-ai
w
how can i configure prometheus adapter to enable livekit_egress_available custom metric? Show me every step with the yaml files detailed.
t
Thanks for reaching out, Alberto. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking for every step with full YAML to configure the Prometheus Adapter so the LiveKit metric
livekit_egress_available
is exposed as a Kubernetes custom metric. I’ll walk you through a complete setup: enable metrics on Egress, ensure Prometheus scrapes it, configure the Prometheus Adapter rules (Helm values file), and show HPAs that use the metric. Quick clarifying question before I give the full YAMLs: are you using Prometheus Operator (kube-prometheus-stack) with ServiceMonitors, or plain Prometheus with scrape configs? Sources: Self-hosting the Egress Service | LiveKit docs
w
plain Prometheus server, i dont use helm. Give me yaml directly for k8s
t
Acknowledged — you’re using plain Prometheus (no Helm). Below are Kubernetes YAML manifests you can apply directly. They: • Enable Prometheus scraping of LiveKit Egress by exposing a Service on the metrics port. • Create a ServiceMonitor-like scrape target for plain Prometheus using a Kubernetes Service and Pod annotations (so Prometheus discovers it via Kubernetes service discovery). • Deploy Prometheus Adapter configured to map the Prometheus metric
livekit_egress_available
into the custom metrics API. • Provide two HPAs: one that uses a per-pod Pods metric and one that uses a cluster-wide External metric. Apply these in order and edit namespace/name values to match your cluster. 1) Namespace (adjust name if you already have one)
Copy code
apiVersion: v1
kind: Namespace
metadata:
  name: livekit
2) LiveKit Egress Deployment (excerpt with metrics port and labels) — ensure your real image/args/config mount as needed
Copy code
apiVersion: apps/v1
kind: Deployment
metadata:
  name: livekit-egress
  namespace: livekit
  labels:
    app: livekit-egress
spec:
  replicas: 2
  selector:
    matchLabels:
      app: livekit-egress
  template:
    metadata:
      labels:
        app: livekit-egress
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "6789"
        prometheus.io/path: "/metrics"
    spec:
      containers:
        - name: egress
          image: your-registry/livekit-egress:latest
          ports:
            - containerPort: 6789
              name: metrics
          env:
            - name: PROMETHEUS_PORT
              value: "6789"
          # mount your egress config with prometheus_port enabled
3) Service exposing metrics port (used by Prometheus k8s SD)
Copy code
apiVersion: v1
kind: Service
metadata:
  name: livekit-egress-metrics
  namespace: livekit
  labels:
    app: livekit-egress
spec:
  selector:
    app: livekit-egress
  ports:
    - name: metrics
      port: 6789
      targetPort: 6789
4) Prometheus config snippet to add to your plain Prometheus server scrape configs (add to your Prometheus server ConfigMap or file). This uses Kubernetes service discovery to find the Service above:
Copy code
# Add this job to your Prometheus scrape_configs
- job_name: 'kubernetes-service-endpoints-livekit-egress'
  kubernetes_sd_configs:
    - role: endpoints
  relabel_configs:
    - source_labels: [__meta_kubernetes_service_label_app]
      regex: livekit-egress
      action: keep
    - source_labels: [__meta_kubernetes_endpoint_port_name]
      regex: metrics
      action: keep
If your Prometheus is configured via a ConfigMap in k8s, patch that ConfigMap with this job and reload Prometheus. 5) Prometheus Adapter Deployment + RBAC + ConfigMap mapping rules (no Helm). The adapter needs: • ClusterRole/Binding for reading metrics and serving custom metrics API. • A ConfigMap containing the adapter rules mapping
livekit_egress_available
to custom metrics. a) Adapter ConfigMap (mapping rules)
Copy code
apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-adapter-config
  namespace: monitoring
data:
  config.yaml: |
    rules:
      custom:
        - seriesQuery: 'livekit_egress_available{namespace!="",pod!=""}'
          name:
            matches: "livekit_egress_available"
            as: "livekit_egress_available"
          metricsQuery: 'avg_over_time(livekit_egress_available{<<.LabelMatchers>>}[2m])'
          resources:
            overrides:
              namespace: {resource: "namespace"}
              pod: {resource: "pod"}
        - seriesQuery: 'livekit_egress_available'
          name:
            as: "livekit_egress_available"
          metricsQuery: 'sum(livekit_egress_available)'
          resources:
            template: {resource: "deployment"}
b) RBAC for adapter
Copy code
apiVersion: v1
kind: ServiceAccount
metadata:
  name: prometheus-adapter
  namespace: monitoring
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: prometheus-adapter
rules:
  - apiGroups: [""]
    resources: ["pods","namespaces"]
    verbs: ["get","list","watch"]
  - apiGroups: ["metrics.k8s.io","custom.metrics.k8s.io","external.metrics.k8s.io"]
    resources: ["*"]
    verbs: ["*"]
  - apiGroups: [""]
    resources: ["services","endpoints"]
    verbs: ["get","list","watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: prometheus-adapter
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: prometheus-adapter
subjects:
  - kind: ServiceAccount
    name: prometheus-adapter
    namespace: monitoring
c) Prometheus Adapter Deployment and Service
Copy code
apiVersion: apps/v1
kind: Deployment
metadata:
  name: prometheus-adapter
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus-adapter
  template:
    metadata:
      labels:
        app: prometheus-adapter
    spec:
      serviceAccountName: prometheus-adapter
      containers:
        - name: prometheus-adapter
          image: quay.io/coreos/k8s-prometheus-adapter-amd64:v0.8.4
          args:
            - --config=/etc/adapter/config.yaml
            - --metrics-relist-interval=30s
            - --prometheus-url=http://prometheus.monitoring.svc:9090
          volumeMounts:
            - name: config
              mountPath: /etc/adapter
              readOnly: true
      volumes:
        - name: config
          configMap:
            name: prometheus-adapter-config
---
apiVersion: v1
kind: Service
metadata:
  name: prometheus-adapter
  namespace: monitoring
spec:
  selector:
    app: prometheus-adapter
  ports:
    - name: http
      port: 443
      targetPort: 6443
Important: set
--prometheus-url
to your Prometheus service URL (example above assumes
prometheus.monitoring.svc:9090
). Adjust image version as desired. 6) Verify custom metrics API is populated After the adapter starts and reads metrics from Prometheus, verify: • List available metrics: kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1" | jq • Query pod-scoped metric: kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/livekit/pods/*/livekit_egress_available" 7) HPA examples a) HPA using pod-scoped Pods metric (per-pod average)
Copy code
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: livekit-egress-hpa
  namespace: livekit
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: livekit-egress
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Pods
      pods:
        metric:
          name: livekit_egress_available
        target:
          type: AverageValue
          averageValue: "1"
b) HPA using External metric (cluster-wide available count)
Copy code
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: livekit-egress-external-hpa
  namespace: livekit
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: livekit-egress
  minReplicas: 1
  maxReplicas: 10
  metrics:
    - type: External
      external:
        metric:
          name: livekit_egress_available
        target:
          type: Value
          value: "3"
Notes and tips: • Ensure the LiveKit egress process exposes
livekit_egress_available
on the metrics endpoint and the egress pods are being scraped by Prometheus. • The adapter rule
metricsQuery
examples use
avg_over_time(...)
for pod-scoped smoothing and
sum(...)
for cluster totals — adjust time windows and queries to your needs. • If your Prometheus is not reachable at the URL configured in the adapter, the adapter will fail to fetch series; confirm network/DNS from the adapter pod. • Replace namespaces (
monitoring
,
livekit
) and service names with your actual names. Would you like me to: • Produce a single combined YAML file you can apply at once? • Tune the adapter
metricsQuery
time windows or seriesQuery filters for a specific label setup on your egress pods?