Funkwhale chart rewrite to combine API/front pods

Doing this allows the reverse proxy to use a unix socket for
communication
This commit is contained in:
Alexander "Ace" Olofsson 2019-07-08 22:46:21 +02:00
parent c748ab39d0
commit a3977d8571
No known key found for this signature in database
GPG key ID: D439C9470CB04C73
12 changed files with 109 additions and 166 deletions

View file

@ -1,5 +1,7 @@
---
apiVersion: v1
appVersion: "0.19.1"
description: A social platform to enjoy and share music
icon: https://funkwhale.audio/favicon.png
name: funkwhale
version: 0.1.1
version: 0.2.0

View file

@ -1,3 +1,4 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
@ -11,7 +12,7 @@ metadata:
data:
nginx.conf: |
upstream funkwhale-api {
server {{ include "funkwhale.fullname" . }}-api:5000;
server unix:/run/funkwhale/funkwhale.sock;
}
map $http_upgrade $connection_upgrade {

View file

@ -1,3 +1,4 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
@ -8,8 +9,6 @@ metadata:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
data:
FUNKWHALE_API_IP: 0.0.0.0
FUNKWHALE_API_PORT: "5000"
FUNKWHALE_HOSTNAME: {{ .Values.ingress.host }}
FUNKWHALE_PROTOCOL: {{ .Values.ingress.protocol }}
REVERSE_PROXY_TYPE: nginx

View file

@ -1,83 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "funkwhale.fullname" . }}-api
labels:
app.kubernetes.io/name: {{ include "funkwhale.name" . }}
helm.sh/chart: {{ include "funkwhale.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
audio.funkwhale/component: api
spec:
replicas: {{ .Values.api.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "funkwhale.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
audio.funkwhale/component: api
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "funkwhale.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
audio.funkwhale/component: api
spec:
containers:
- name: api
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
envFrom:
- configMapRef:
name: {{ include "funkwhale.fullname" . }}
- secretRef:
name: {{ include "funkwhale.fullname" . }}
ports:
- name: api
containerPort: 5000
protocol: TCP
# livenessProbe:
# httpGet:
# path: /
# port: http
readinessProbe:
tcpSocket:
port: api
{{- if or .Values.persistence.enabled .Values.api.extraVolumeMounts }}
volumeMounts:
{{- if .Values.persistence.enabled }}
- name: data
mountPath: /srv/funkwhale/data
{{- end }}
{{- range .Values.api.extraVolumeMounts }}
- name: {{ .name }}
mountPath: {{ .mountPath }}
readOnly: {{ .readOnly }}
{{- end }}
{{- end }}
resources:
{{- toYaml .Values.api.resources | nindent 12 }}
{{- with .Values.api.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.api.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.api.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if or .Values.persistence.enabled .Values.api.extraVolumeMounts }}
volumes:
{{- if .Values.persistence.enabled }}
- name: data
persistentVolumeClaim:
claimName: {{ include "funkwhale.fullname" . }}
{{- end }}
{{- range .Values.api.extraVolumeMounts }}
- name: {{ .name }}
persistentVolumeClaim:
claimName: {{ .existingClaim }}
{{- end }}
{{- end }}

View file

@ -1,3 +1,4 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:

View file

@ -1,3 +1,4 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
@ -39,11 +40,12 @@ spec:
name: {{ include "funkwhale.fullname" . }}
- secretRef:
name: {{ include "funkwhale.fullname" . }}
{{- if .Values.persistence.enabled }}
volumeMounts:
- mountPath: /srv/funkwhale/data
name: data
{{- end }}
{{- if .Values.celery.worker.extraVolumeMounts }}
{{ toYaml .Values.celery.worker.extraVolumeMounts | indent 12 }}
{{- end }}
resources:
{{- toYaml .Values.celery.worker.resources | nindent 12 }}
{{- with .Values.celery.worker.nodeSelector }}
@ -59,16 +61,16 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
{{- if .Values.persistence.enabled }}
- name: data
persistentVolumeClaim:
claimName: {{ include "funkwhale.fullname" . }}
{{- end }}
- name: config
configMap:
name: {{ include "funkwhale.fullname" . }}-front
{{- range .Values.celery.worker.extraVolumeMounts }}
- name: {{ .name }}
- name: data
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ .existingClaim }}
claimName: {{ .Values.persistence.existingClaim | default (include "funkwhale.fullname" .) }}
{{- else }}
emptyDir: {}
{{- end }}
{{- if .Values.celery.worker.extraVolumes }}
{{ toYaml .Values.celery.worker.extraVolumes | indent 8 }}
{{- end }}

View file

@ -1,58 +1,84 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "funkwhale.fullname" . }}-front
name: {{ include "funkwhale.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "funkwhale.name" . }}
helm.sh/chart: {{ include "funkwhale.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
audio.funkwhale/component: front
audio.funkwhale/component: app
spec:
replicas: {{ .Values.front.replicaCount }}
replicas: {{ .Values.api.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "funkwhale.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
audio.funkwhale/component: front
audio.funkwhale/component: app
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "funkwhale.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
audio.funkwhale/component: front
audio.funkwhale/component: app
spec:
initContainers:
- name: front
containers:
- name: funkwhale
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- sh
- -c
- |
- |-
set -x
cp -r frontend/* /frontend/
cp -r /usr/lib/python3.6/site-packages/django/contrib/admin/static/* /static/
cp -r /app/funkwhale_api/static/* /static/
# Copy frontend files for the front pod
cp -r frontend/* /srv/funkwhale/frontend/
# Ensure the server binds to a unix socket
if [ -e compose/django/daphne.sh ]; then
sed -e 's!-b 0.0.0.0 -p 5000!-u /run/funkwhale/funkwhale.sock!' -i compose/django/daphne.sh
compose/django/entrypoint.sh compose/django/daphne.sh
else
sed -e 's!0.0.0.0:5000!unix:/run/funkwhale/funkwhale.sock!' -i compose/django/server.sh
compose/django/entrypoint.sh compose/django/server.sh
fi
envFrom:
- configMapRef:
name: {{ include "funkwhale.fullname" . }}
- secretRef:
name: {{ include "funkwhale.fullname" . }}
{{- if or .Values.persistence.enabled .Values.api.extraVolumeMounts }}
volumeMounts:
- mountPath: /frontend
name: frontend
- mountPath: /static
- mountPath: /run/funkwhale
name: funkwhale-sock
- mountPath: /srv/funkwhale/data/static/
name: static
- mountPath: /srv/funkwhale/frontend
name: frontend
- name: data
mountPath: /srv/funkwhale/data
{{- if .Values.extraVolumeMounts }}
{{ toYaml .Values.extraVolumeMounts | indent 12 }}
{{- end }}
{{- end }}
resources:
limits:
cpu: 50m
memory: 50Mi
containers:
{{- toYaml .Values.api.resources | nindent 12 }}
- name: nginx
image: "{{ .Values.front.image.repository }}:{{ .Values.front.image.tag }}"
imagePullPolicy: {{ .Values.front.image.pullPolicy }}
command:
- sh
- -c
- |
- |-
# Instantiate the nginx template
envsubst "`env | awk -F = '{printf \" $%s\", $1}'`" < /etc/nginx/funkwhale.template > /etc/nginx/conf.d/default.conf
# Add a hardcoded resolver configuration to ease S3 usage
echo "resolver $(grep nameserver /etc/resolv.conf | head -n1 | awk '{print $2}');" > /etc/nginx/conf.d/resolver.conf
# Launch nginx
nginx -g 'daemon off;'
envFrom:
- configMapRef:
@ -68,49 +94,53 @@ spec:
tcpSocket:
port: http
volumeMounts:
- mountPath: /frontend
name: frontend
- mountPath: /srv/funkwhale/data/static/
name: static
{{- if .Values.persistence.enabled }}
- mountPath: /run/funkwhale
name: funkwhale-sock
- mountPath: /srv/funkwhale/data
name: data
{{- end }}
- mountPath: /frontend
name: frontend
readOnly: true
- mountPath: /etc/nginx/funkwhale_proxy.conf
name: config
subPath: proxy.conf
readOnly: true
- mountPath: /etc/nginx/funkwhale.template
name: config
subPath: nginx.conf
resources:
{{- toYaml .Values.front.resources | nindent 12 }}
{{- with .Values.front.nodeSelector }}
readOnly: true
{{- if .Values.front.extraVolumeMounts }}
{{ toYaml .Values.front.extraVolumeMounts | indent 12 }}
{{- end }}
{{- with .Values.api.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.front.affinity }}
{{- with .Values.api.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.front.tolerations }}
{{- with .Values.api.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: funkwhale-sock
emptyDir: {}
- name: frontend
emptyDir: {}
- name: static
emptyDir: {}
{{- if .Values.persistence.enabled }}
- name: data
persistentVolumeClaim:
claimName: {{ include "funkwhale.fullname" . }}
{{- end }}
- name: config
configMap:
name: {{ include "funkwhale.fullname" . }}-front
{{- range .Values.front.extraVolumeMounts }}
- name: {{ .name }}
- name: data
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ .existingClaim }}
{{- end }}
claimName: {{ .Values.persistence.existingClaim | default (include "funkwhale.fullname" .) }}
{{- else }}
emptyDir: {}
{{- end }}
{{- if .Values.api.extraVolumes }}
{{ toYaml .Values.api.extraVolumes | indent 8 }}
{{- end }}

View file

@ -1,5 +1,6 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "funkwhale.fullname" . -}}
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
@ -30,6 +31,6 @@ spec:
paths:
- path: /
backend:
serviceName: {{ $fullName }}-front
serviceName: {{ $fullName }}
servicePort: http
{{- end }}

View file

@ -1,4 +1,5 @@
{{- if .Values.persistence.enabled }}
{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
@ -10,7 +11,7 @@ metadata:
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
accessModes:
- ReadWriteMany
- {{ .Values.persistence.accessMode }}
resources:
requests:
storage: {{ .Values.persistence.size | quote }}

View file

@ -1,20 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "funkwhale.fullname" . }}-api
labels:
app.kubernetes.io/name: {{ include "funkwhale.name" . }}
helm.sh/chart: {{ include "funkwhale.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
type: ClusterIP
ports:
- port: 5000
targetPort: api
protocol: TCP
name: api
selector:
app.kubernetes.io/name: {{ include "funkwhale.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
audio.funkwhale/component: api

View file

@ -1,7 +1,8 @@
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "funkwhale.fullname" . }}-front
name: {{ include "funkwhale.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "funkwhale.name" . }}
helm.sh/chart: {{ include "funkwhale.chart" . }}
@ -17,4 +18,4 @@ spec:
selector:
app.kubernetes.io/name: {{ include "funkwhale.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
audio.funkwhale/component: front
audio.funkwhale/component: app

View file

@ -1,7 +1,7 @@
# Default values for funkwhale.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
---
image:
repository: funkwhale/funkwhale
tag: 0.19.1
@ -10,6 +10,8 @@ image:
nameOverride: ""
fullnameOverride: ""
replicaCount: 1
service:
type: ClusterIP
port: 80
@ -72,12 +74,14 @@ extraSecret: {}
persistence:
enabled: false
# existingClaim: netbox-data
# storageClass: "-"
accessMode: ReadWriteMany
size: 1Gi
storageClass: "-"
s3:
enabled: false
proxy: false
proxy: true
accessKey: ''
secretKey: ''
@ -87,7 +91,7 @@ s3:
# url: http://s3.example.com
api:
replicaCount: 1
# replicaCount: 1
# Additional mounts to add to the API pod
extraVolumeMounts: []
@ -95,6 +99,8 @@ api:
# mountPath: /srv/funkwhale/data/music
# readOnly: true
# existingClaim: volume-claim
extraVolumes: []
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
@ -115,7 +121,7 @@ api:
affinity: {}
front:
replicaCount: 1
# replicaCount: 1
image:
repository: nginx
@ -129,6 +135,8 @@ front:
# readOnly: true
# existingClaim: volume-claim
extraVolumes: []
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little