K8S: Support fsnotify and reload when ConfigMap update #1635
Closed
Description
K8S uses ConfigMap to store configuration files, for example:
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: srs-config
data:
srs.conf: |-
listen 1935;
max_connections 1000;
daemon off;
http_api {
enabled on;
listen 1985;
}
http_server {
enabled on;
listen 8080;
}
vhost __defaultVhost__ {
http_remux {
enabled on;
}
hls {
enabled on;
}
}
EOF
ConfigMap will be mounted as a volume and become a configuration file:
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: srs-deploy
labels:
app: srs
spec:
replicas: 1
selector:
matchLabels:
app: srs
template:
metadata:
labels:
app: srs
spec:
volumes:
- name: config-volume
configMap:
name: srs-config
containers:
- name: srs
image: ossrs/srs:3
imagePullPolicy: IfNotPresent
ports:
- containerPort: 1935
- containerPort: 1985
- containerPort: 8080
volumeMounts:
- name: config-volume
mountPath: /usr/local/srs/conf
EOF
You can view the running pods:
Mac:trunk chengli.ycl$ pod=`kubectl get po|grep srs-deploy|awk '{print $1}'`
Mac:trunk chengli.ycl$ kubectl exec $pod -- cat conf/srs.conf && echo ""
listen 1935;
max_connections 1000;
daemon off;
http_api {
enabled on;
listen 1985;
}
http_server {
enabled on;
listen 8080;
}
vhost __defaultVhost__ {
http_remux {
enabled on;
}
hls {
enabled on;
}
}
When ConfigMap changes, you can use fsnotify to receive notifications of file changes, thereby triggering the reload of SRS.
TRANS_BY_GPT3