Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

livekit-ingress chart #51

Merged
merged 7 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions deploy-ingress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -euxo pipefail

rm -rf build
mkdir -p build
helm package ingress --destination build
cd build
AWS_REGION=us-east-1 helm s3 push --relative ./ingress*.tgz livekit

aws cloudfront create-invalidation --distribution-id E2MJ94T12TAUZU --paths "/*"
79 changes: 79 additions & 0 deletions ingress-sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
replicaCount: 1

# Suggested value for gracefully terminate the pod: 1 hour
terminationGracePeriodSeconds: 3600
real-danm marked this conversation as resolved.
Show resolved Hide resolved

ingress:
api_key: "server-api-key"
api_secret: "server-api-secret"
ws_url: "ws://livekit-host:<port>"
log_level: info
health_port: 7888
prometheus_port: 7889
http_relay_port: 9090
rtmp_port: 1935

redis:
address: <redis_host:port>
# db: 0
# username:
# password:
# use_tls: false

cpu_cost:
rtmp_cpu_cost: 2.0

# autoscaling requires resources to be defined
autoscaling:
# set to true to enable autoscaling. when set, ignores replicaCount
enabled: false
minReplicas: 1
maxReplicas: 5
targetCPUUtilizationPercentage: 60
# targetMemoryUtilizationPercentage: 60
# for use with prometheus adapter - the ingress service outputs a prometheus metric called livekit_ingress_available
# this can be used to ensure a certain number or percentage of instances are available
# custom:
# metricName: my_metric_name
# targetAverageValue: 70

# if ingress should run only on specific nodes
# this can be used to isolate designated nodes
nodeSelector: {}
# node.kubernetes.io/instance-type: c5.2xlarge

resources: {}
# requests:
# cpu: 5000m
# memory: 1024Mi
# limits:
# cpu: 8000m
# memory: 2048Mi

serviceAccount:
# Specifies whether a service account should be created
create: false
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""

podAnnotations:
sidecar.istio.io/inject: "false"
linkerd.io/inject: disabled

podSecurityContext: {}
# fsGroup: 2000

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

tolerations: []

affinity: {}
23 changes: 23 additions & 0 deletions ingress/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
9 changes: 9 additions & 0 deletions ingress/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v2
name: ingress
description: Ingress is used by LiveKit to stream and record rooms.
real-danm marked this conversation as resolved.
Show resolved Hide resolved
type: application
version: 0.0.1
appVersion: "v0.0.1"

sources:
- https://github.com/livekit/ingress
5 changes: 5 additions & 0 deletions ingress/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-------------------------------------------------------------------------------

LiveKit Ingress {{ .Values.image.tag | default .Chart.AppVersion }} has been deployed!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful to display text around any DNS mapping that they should perform. How do they get the IP address of the load balancer that's created? (a kubectl command to find out would be useful)

@biglittlebigben how does LiveKit server know what IP/URL to use for this ingress instance? when CreateIngress


-------------------------------------------------------------------------------
62 changes: 62 additions & 0 deletions ingress/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "ingress.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "ingress.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "ingress.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "ingress.labels" -}}
helm.sh/chart: {{ include "ingress.chart" . }}
{{ include "ingress.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "ingress.selectorLabels" -}}
app.kubernetes.io/name: {{ include "ingress.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "ingress.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "ingress.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
7 changes: 7 additions & 0 deletions ingress/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "ingress.fullname" . }}
data:
config.yaml: |
{{ toYaml .Values.ingress | indent 4 }}
82 changes: 82 additions & 0 deletions ingress/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "ingress.fullname" . }}
labels:
{{- include "ingress.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "ingress.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
labels:
{{- include "ingress.selectorLabels" . | nindent 8 }}
spec:
serviceAccountName: {{ include "ingress.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: INGRESS_CONFIG_BODY
valueFrom:
configMapKeyRef:
name: {{ include "ingress.fullname" . }}
key: config.yaml
ports:
{{- if .Values.ingress.health_port }}
- name: health
containerPort: {{ .Values.ingress.health_port }}
protocol: TCP
{{- end }}
{{- if .Values.ingress.http_relay_port }}
- name: http-relay
containerPort: {{ .Values.ingress.http_relay_port }}
protocol: TCP
{{- end }}
{{- if .Values.ingress.rtmp_port }}
- name: rtmp-port
containerPort: {{ .Values.ingress.rtmp_port }}
protocol: TCP
{{- end }}
{{- if .Values.ingress.prometheus_port }}
- name: metrics
containerPort: {{ .Values.ingress.prometheus_port }}
protocol: TCP
{{- end }}
livenessProbe:
httpGet:
path: /
port: health
readinessProbe:
httpGet:
path: /
port: health
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
58 changes: 58 additions & 0 deletions ingress/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{{- if .Values.autoscaling.enabled }}
{{- if semverCompare ">=1.23-0" .Capabilities.KubeVersion.GitVersion }}
apiVersion: autoscaling/v2
{{- else }}
apiVersion: autoscaling/v2beta1
{{- end }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "ingress.fullname" . }}
labels:
{{- include "ingress.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "ingress.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
{{- if semverCompare ">=1.23-0" .Capabilities.KubeVersion.GitVersion }}
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- else }}
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
{{- if semverCompare ">=1.23-0" .Capabilities.KubeVersion.GitVersion }}
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- else }}
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
{{- if .Values.autoscaling.custom }}
- type: Pods
pods:
{{- if semverCompare ">=1.23-0" .Capabilities.KubeVersion.GitVersion }}
metric:
name: {{ .Values.autoscaling.custom.metricName }}
target:
type: AverageValue
averageValue: {{ .Values.autoscaling.custom.targetAverageValue }}
{{- else }}
metricName: {{ .Values.autoscaling.custom.metricName }}
targetAverageValue: {{ .Values.autoscaling.custom.targetAverageValue }}
{{- end }}
{{- end }}
{{- end }}
16 changes: 16 additions & 0 deletions ingress/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "ingress.fullname" . }}
labels: {{- include "ingress.labels" . | nindent 4 }}
spec:
type: LoadBalancer
ports:
- port: {{ .Values.loadBalancer.servicePort }}
protocol: TCP
name: ws
- port: {{ .Values.ingress.rtmp_port }}
protocol: TCP
name: rtmp
selector:
{{- include "ingress.selectorLabels" . | nindent 4 }}
12 changes: 12 additions & 0 deletions ingress/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "ingress.serviceAccountName" . }}
labels:
{{- include "ingress.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
Loading