Skip to content

Commit

Permalink
Let oryx app running in three containers.
Browse files Browse the repository at this point in the history
three containers running in a single pod. The three containers are oryx
platform(including oryx backend and front-end WebUI), redis and srs.
The purpose of isolated containers is to support livenessProbe and
readinessProbe for each processes, oryx platform, redis, srs.
  • Loading branch information
suzp1984 committed Jul 30, 2024
1 parent d69a8a9 commit da2541a
Show file tree
Hide file tree
Showing 4 changed files with 322 additions and 2 deletions.
4 changes: 2 additions & 2 deletions oryx/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: oryx
appVersion: "5.14.19"
version: 1.0.7
appVersion: "5.15.20"
version: 1.0.8
description: Oryx(SRS Stack) is an all-in-one, one-click, and open-source video solution for creating online
services on cloud or self-hosting. Built with SRS, FFmpeg, and WebRTC, it supports various protocols
and offers features like authentication, multi-platform streaming, recording, transcoding, virtual
Expand Down
2 changes: 2 additions & 0 deletions oryx/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if not .Values.multiContainers.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -123,3 +124,4 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end -}}
311 changes: 311 additions & 0 deletions oryx/templates/multi-containers-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
{{- if .Values.multiContainers.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "srs.fullname" . }}
labels:
{{- include "srs.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "srs.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "srs.selectorLabels" . | nindent 8 }}
spec:
volumes:
- name: srs-pv-storage
persistentVolumeClaim:
claimName: srs-pv-claim
- name: cache-volume
emptyDir: {}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "srs.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
# oryx main application container
- name: oryx
volumeMounts:
- mountPath: "/data"
name: srs-pv-storage
{{- if .Values.persistence.subPath }}
subPath: {{ .Values.persistence.subPath | quote }}
{{- end }}
- mountPath: "/usr/local/oryx/platform/containers/objs/nginx/html"
name: cache-volume
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
# use script to wait redis and srs start.
command: # ["./platform"]
- bash
- -c
- |-
echo "--- oryx container entry ---"
echo "1. wait redis to start"
until redis-cli ping
do
echo "wait redis server start ..."
sleep 1
done
echo " redis server started."
echo "2. wait srs to start"
until [[ -f ./containers/data/srs.pid ]]
do
echo "wait srs start ..."
sleep 1
done
echo " srs server started."
echo "3. start oryx platform"
./platform &
if [[ $? -ne 0 ]]; then echo "Start platform failed"; exit 1; fi
handle_signals() {
echo "Platform: Signal $1 received. Cleaning up and exiting..."
exit 0
}
trap 'handle_signals SIGTERM' SIGTERM
trap 'handle_signals SIGINT' SIGINT
while true; do
sleep 3
if [[ $(ps aux |grep platform |grep -v grep |grep -v usr |grep -q platform || echo no) == no ]]; then
echo "Platform stopped, exit."
break
fi
done
exit 1
ports:
- name: http
containerPort: 2022
protocol: TCP
- name: https
containerPort: 2443
protocol: TCP
env:
# The general default config.
- name: SRS_PLATFORM
value: "helm"
# Overwrite the config by conf.
{{- range $key, $value := .Values.conf }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
# Overwrite the config by env.
{{- range .Values.env }}
- name: {{ .name }}
value: {{ .value | quote }}
{{- end }}
# For multiple instances expose different ports.
- name: RTMP_PORT
value: {{ .Values.service.rtmp | quote }}
- name: SRT_PORT
value: {{ .Values.service.srt | quote }}
- name: RTC_PORT
value: {{ .Values.service.rtc | quote }}
# Enable self-sign certificate by default.
- name: AUTO_SELF_SIGNED_CERTIFICATE
value: "on"
# Enable dns name lookup.
- name: NAME_LOOKUP
value: "on"
livenessProbe:
httpGet:
path: /terraform/v1/host/versions
port: http
readinessProbe:
httpGet:
path: /terraform/v1/host/versions
port: http
startupProbe:
httpGet:
path: /terraform/v1/host/versions
port: http
initialDelaySeconds: 5
failureThreshold: 3
periodSeconds: 10
resources:
{{- toYaml .Values.resources | nindent 12 }}
# redis container
- name: redis
volumeMounts:
- mountPath: "/data"
name: srs-pv-storage
{{- if .Values.persistence.subPath }}
subPath: {{ .Values.persistence.subPath | quote }}
{{- end }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: #["./auto/start_redis"]
- bash
- -c
- |-
./auto/start_redis
stop_services() {
./auto/before_stop
./auto/stop_redis
}
handle_signals() {
echo "Platform: Signal $1 received. Cleaning up and exiting..."
stop_services
exit 0
}
trap 'handle_signals SIGTERM' SIGTERM
trap 'handle_signals SIGINT' SIGINT
while true; do
sleep 3
if [[ $(ps aux |grep redis |grep -q server || echo no) == no ]]; then
echo "Redis server stopped, exit."
break
fi
done
stop_services
exit 1
ports:
- name: redis
containerPort: 6379 # the redis default port
protocol: TCP
livenessProbe:
exec:
command:
- redis-cli
- ping
initialDelaySeconds: 5
periodSeconds: 10
- name: srs
volumeMounts:
- mountPath: "/data"
name: srs-pv-storage
{{- if .Values.persistence.subPath }}
subPath: {{ .Values.persistence.subPath | quote }}
{{- end }}
- mountPath: "/usr/local/oryx/platform/containers/objs/nginx/html"
name: cache-volume
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: # ["./auto/start_srs"]
- bash
- -c
- |-
./auto/start_srs
cp ./containers/objs/srs.pid ./containers/data/srs.pid
stop_services() {
./auto/stop_srs
rm ./containers/data/srs.pid
}
handle_signals() {
echo "Signal $1 received. Cleaning up and exiting..."
stop_services
exit 0
}
trap 'handle_signals SIGTERM' SIGTERM
trap 'handle_signals SIGINT' SIGINT
while true; do
sleep 3
if [[ $(ps aux |grep srs |grep -q conf || echo no) == no ]]; then
echo "SRS server stopped, exit."
break
fi
done
stop_services
exit 1
ports:
- name: rtmp
containerPort: 1935
protocol: TCP
- name: api
containerPort: 1985
protocol: TCP
- name: http
containerPort: 8080
protocol: TCP
- name: srt
containerPort: 10080
protocol: UDP
- name: rtc
containerPort: 8000
protocol: UDP
env:
# The general default config.
- name: SRS_PLATFORM
value: "helm"
# Overwrite the config by conf.
{{- range $key, $value := .Values.conf }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
# Overwrite the config by env.
{{- range .Values.env }}
- name: {{ .name }}
value: {{ .value | quote }}
{{- end }}
# Overwrite by special item.
{{- if .Values.candidate }}
- name: SRS_RTC_SERVER_CANDIDATE
value: {{ .Values.candidate | quote }}
{{- end }}
# For Oryx, we resolve the ip in platform.
- name: SRS_RTC_SERVER_API_AS_CANDIDATES
value: "off"
# For Oryx, never detect network ip, because it runs in docker, and the ip is private.
- name: SRS_RTC_SERVER_USE_AUTO_DETECT_NETWORK_IP
value: "off"
# For Oryx, should always enable daemon.
- name: SRS_DAEMON
value: "on"
- name: SRS_HTTP_API_LISTEN
value: "1985"
livenessProbe:
httpGet:
path: /api/v1/versions
port: api
periodSeconds: 10
readinessProbe:
httpGet:
path: /api/v1/versions
port: api
periodSeconds: 10
startupProbe:
httpGet:
path: /api/v1/versions
port: api
initialDelaySeconds: 2
failureThreshold: 3
periodSeconds: 10
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end -}}
7 changes: 7 additions & 0 deletions oryx/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ image:
tag: ""
pullPolicy: IfNotPresent

# simple set replicaCount more than one don't make sense, because oryx is stateful app.
replicaCount: 1

# muti containers mean the oryx platform, redis, and srs in its own container.
multiContainers:
# Specifies whether deploy oryx as single container or multi containers in a pod.
enabled: false

# The configuration for SRS can be overridden by environment variables.
# See https://github.com/ossrs/srs/blob/develop/trunk/conf/full.conf
conf:
Expand Down Expand Up @@ -107,6 +113,7 @@ resources: {}
# cpu: 100m
# memory: 128Mi

# simple open autoscaling don't make sense, because oryx is stateful app.
autoscaling:
enabled: false
minReplicas: 1
Expand Down

0 comments on commit da2541a

Please sign in to comment.