From ef4175a8d2feb40a278997fb14193b10377f205c Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Sun, 18 Oct 2026 17:33:22 +0200 Subject: [PATCH] Own and promote the coturn Helm chart --- .gitea/workflows/chart.yml | 44 +++++++++++++++++ chart/Chart.yaml | 6 +++ chart/templates/services.yaml | 48 ++++++++++++++++++ chart/templates/workload.yaml | 92 +++++++++++++++++++++++++++++++++++ chart/values.yaml | 26 ++++++++++ scripts/chart-version.sh | 7 +++ 6 files changed, 223 insertions(+) create mode 100644 .gitea/workflows/chart.yml create mode 100644 chart/Chart.yaml create mode 100644 chart/templates/services.yaml create mode 100644 chart/templates/workload.yaml create mode 100644 chart/values.yaml create mode 100755 scripts/chart-version.sh diff --git a/.gitea/workflows/chart.yml b/.gitea/workflows/chart.yml new file mode 100644 index 0000000..aa87112 --- /dev/null +++ b/.gitea/workflows/chart.yml @@ -0,0 +1,44 @@ +name: Publish and promote Helm chart +on: + push: + pull_request: +jobs: + chart: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: {fetch-depth: 0} + - uses: azure/setup-helm@v4 + - name: Lint and render + run: | + helm lint chart --set externalIP=192.0.2.1 + helm template coturn chart --set externalIP=192.0.2.1 >/dev/null + - name: Publish + if: gitea.ref == 'refs/heads/main' + run: | + version=$(./scripts/chart-version.sh) + echo "CHART_VERSION=${version}" >> "${GITHUB_ENV}" + mkdir -p dist + helm package chart --destination dist --version "${version}" + curl --fail-with-body --user "${{ secrets.PACKAGE_USERNAME }}:${{ secrets.PACKAGE_TOKEN }}" \ + --upload-file "dist/coturn-${version}.tgz" \ + https://code.brunner.ninja/api/packages/feedc0de/helm/api/charts + - name: Check out GitOps + if: gitea.ref == 'refs/heads/main' + uses: actions/checkout@v4 + with: + repository: feedc0de/homelab-gitops + ref: main + token: ${{ secrets.GITOPS_TOKEN }} + path: homelab-gitops + - name: Promote + if: gitea.ref == 'refs/heads/main' + working-directory: homelab-gitops + run: | + ./scripts/update-chart-version.sh coturn "${CHART_VERSION}" + git config user.name feedc0de + git config user.email feedc0de@users.noreply.code.brunner.ninja + git add bootstrap/coturn.yaml + if git diff --cached --quiet; then exit 0; fi + git commit -m "Deploy coturn chart ${CHART_VERSION}" + git push origin HEAD:main diff --git a/chart/Chart.yaml b/chart/Chart.yaml new file mode 100644 index 0000000..29f1b79 --- /dev/null +++ b/chart/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: coturn +description: TURN/STUN relay with TCP, UDP, TLS, and configurable relay ports +type: application +version: 0.1.0 +appVersion: 4.10.0-r1 diff --git a/chart/templates/services.yaml b/chart/templates/services.yaml new file mode 100644 index 0000000..4ff095f --- /dev/null +++ b/chart/templates/services.yaml @@ -0,0 +1,48 @@ +{{- range $protocol := list "tcp" "udp" }} +{{- $protocolAnnotations := ternary $.Values.service.tcpAnnotations $.Values.service.udpAnnotations (eq $protocol "tcp") }} +{{- $annotations := merge (dict) $.Values.service.commonAnnotations $protocolAnnotations }} +apiVersion: v1 +kind: Service +metadata: + name: coturn-{{ $protocol }} + labels: + app.kubernetes.io/name: coturn + app.kubernetes.io/instance: coturn + {{- with $annotations }} + annotations: {{- toYaml . | nindent 4 }} + {{- end }} +spec: + type: LoadBalancer + {{- with $.Values.service.loadBalancerIP }} + loadBalancerIP: {{ . }} + {{- end }} + externalTrafficPolicy: Local + selector: + app.kubernetes.io/name: coturn + app.kubernetes.io/instance: coturn + ports: + - {name: "{{ $protocol }}", port: 3478, targetPort: "{{ $protocol }}", protocol: "{{ upper $protocol }}"} + - {name: "{{ $protocol }}-tls", port: 5349, targetPort: "{{ $protocol }}-tls", protocol: "{{ upper $protocol }}"} +--- +{{- end }} +apiVersion: v1 +kind: Service +metadata: + name: coturn-relay + {{- $relayAnnotations := merge (dict) .Values.service.commonAnnotations .Values.service.relayAnnotations }} + {{- with $relayAnnotations }} + annotations: {{- toYaml . | nindent 4 }} + {{- end }} +spec: + type: LoadBalancer + {{- with .Values.service.loadBalancerIP }} + loadBalancerIP: {{ . }} + {{- end }} + externalTrafficPolicy: Local + selector: + app.kubernetes.io/name: coturn + app.kubernetes.io/instance: coturn + ports: + {{- range $port := untilStep (int .Values.relay.minPort) (int (add1 .Values.relay.maxPort)) 1 }} + - {name: "relay-{{ $port }}", port: {{ $port }}, targetPort: {{ $port }}, protocol: UDP} + {{- end }} diff --git a/chart/templates/workload.yaml b/chart/templates/workload.yaml new file mode 100644 index 0000000..cc7421a --- /dev/null +++ b/chart/templates/workload.yaml @@ -0,0 +1,92 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: coturn + labels: &labels + app.kubernetes.io/name: coturn + app.kubernetes.io/instance: coturn +automountServiceAccountToken: false +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: coturn + labels: + app.kubernetes.io/name: coturn + app.kubernetes.io/instance: coturn +spec: + replicas: 1 + strategy: {type: Recreate} + selector: + matchLabels: + app.kubernetes.io/name: coturn + app.kubernetes.io/instance: coturn + template: + metadata: + labels: + app.kubernetes.io/name: coturn + app.kubernetes.io/instance: coturn + spec: + serviceAccountName: coturn + automountServiceAccountToken: false + containers: + - name: coturn + image: {{ printf "%s:%s" .Values.image.repository (default .Chart.AppVersion .Values.image.tag) | quote }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: + - --listening-port=3478 + - --tls-listening-port=5349 + - --fingerprint + - --cert=/etc/ssl/certs/cert.pem + - --pkey=/etc/ssl/private/privkey.pem + - --realm={{ .Values.realm }} + - --log-file=stdout + - --no-software-attribute + - --no-cli + - --use-auth-secret + - --static-auth-secret=$(TURN_SHARED_SECRET) + - --external-ip={{ required "externalIP is required" .Values.externalIP }} + - --min-port={{ .Values.relay.minPort }} + - --max-port={{ .Values.relay.maxPort }} + - --no-multicast-peers + env: + - name: TURN_SHARED_SECRET + valueFrom: + secretKeyRef: {name: "{{ .Values.sharedSecret.name }}", key: "{{ .Values.sharedSecret.key }}"} + ports: + - {name: tcp, containerPort: 3478, protocol: TCP} + - {name: udp, containerPort: 3478, protocol: UDP} + - {name: tcp-tls, containerPort: 5349, protocol: TCP} + - {name: udp-tls, containerPort: 5349, protocol: UDP} + readinessProbe: {tcpSocket: {port: tcp}} + livenessProbe: {tcpSocket: {port: tcp}, initialDelaySeconds: 30} + resources: {{- toYaml .Values.resources | nindent 10 }} + securityContext: + allowPrivilegeEscalation: false + capabilities: {add: [NET_BIND_SERVICE], drop: [ALL]} + readOnlyRootFilesystem: true + runAsNonRoot: true + runAsUser: 65534 + volumeMounts: + - {name: certs, mountPath: /etc/ssl/certs, readOnly: true} + - {name: private, mountPath: /etc/ssl/private, readOnly: true} + volumes: + - name: certs + secret: + secretName: {{ .Values.certificate.secretName }} + items: [{key: tls.crt, path: cert.pem}] + - name: private + secret: + secretName: {{ .Values.certificate.secretName }} + items: [{key: tls.key, path: privkey.pem}] +{{- if .Values.certificate.enabled }} +--- +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: {name: coturn} +spec: + secretName: {{ .Values.certificate.secretName }} + dnsNames: [{{ .Values.certificate.dnsName | quote }}] + issuerRef: {group: cert-manager.io, kind: ClusterIssuer, name: "{{ .Values.certificate.issuerName }}"} + usages: [digital signature, key encipherment] +{{- end }} diff --git a/chart/values.yaml b/chart/values.yaml new file mode 100644 index 0000000..bd8f244 --- /dev/null +++ b/chart/values.yaml @@ -0,0 +1,26 @@ +image: + repository: coturn/coturn + tag: "" + pullPolicy: IfNotPresent +realm: example.com +externalIP: "" +relay: + minPort: 49160 + maxPort: 49200 +sharedSecret: + name: turn-shared-secret + key: shared-secret +service: + loadBalancerIP: "" + commonAnnotations: {} + tcpAnnotations: {} + udpAnnotations: {} + relayAnnotations: {} +certificate: + enabled: false + secretName: coturn + dnsName: turn.example.com + issuerName: letsencrypt +resources: + requests: {cpu: 100m, memory: 50Mi} + limits: {cpu: 100m, memory: 50Mi} diff --git a/scripts/chart-version.sh b/scripts/chart-version.sh new file mode 100755 index 0000000..91bdb1f --- /dev/null +++ b/scripts/chart-version.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -eu +description=$(git describe --tags --long --match 'v[0-9]*' --dirty) +case "$description" in *-dirty) echo "refusing dirty tree" >&2; exit 1;; esac +version=${description#v} +case "$version" in *-0-g*) version=${version%%-0-g*};; esac +printf '%s\n' "$version"