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 apiVersion: v1
appVersion: "0.19.1" appVersion: "0.19.1"
description: A social platform to enjoy and share music description: A social platform to enjoy and share music
icon: https://funkwhale.audio/favicon.png
name: funkwhale name: funkwhale
version: 0.1.1 version: 0.2.0

View file

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

View file

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

View file

@ -1,3 +1,4 @@
---
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
@ -39,10 +40,11 @@ spec:
name: {{ include "funkwhale.fullname" . }} name: {{ include "funkwhale.fullname" . }}
- secretRef: - secretRef:
name: {{ include "funkwhale.fullname" . }} name: {{ include "funkwhale.fullname" . }}
{{- if .Values.persistence.enabled }}
volumeMounts: volumeMounts:
- mountPath: /srv/funkwhale/data - mountPath: /srv/funkwhale/data
name: data name: data
{{- if .Values.celery.worker.extraVolumeMounts }}
{{ toYaml .Values.celery.worker.extraVolumeMounts | indent 12 }}
{{- end }} {{- end }}
resources: resources:
{{- toYaml .Values.celery.worker.resources | nindent 12 }} {{- toYaml .Values.celery.worker.resources | nindent 12 }}
@ -59,16 +61,16 @@ spec:
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
volumes: volumes:
{{- if .Values.persistence.enabled }}
- name: data
persistentVolumeClaim:
claimName: {{ include "funkwhale.fullname" . }}
{{- end }}
- name: config - name: config
configMap: configMap:
name: {{ include "funkwhale.fullname" . }}-front name: {{ include "funkwhale.fullname" . }}-front
{{- range .Values.celery.worker.extraVolumeMounts }} - name: data
- name: {{ .name }} {{- if .Values.persistence.enabled }}
persistentVolumeClaim: 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 }} {{- end }}

View file

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

View file

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

View file

@ -1,4 +1,5 @@
{{- if .Values.persistence.enabled }} {{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
---
kind: PersistentVolumeClaim kind: PersistentVolumeClaim
apiVersion: v1 apiVersion: v1
metadata: metadata:
@ -10,7 +11,7 @@ metadata:
app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/managed-by: {{ .Release.Service }}
spec: spec:
accessModes: accessModes:
- ReadWriteMany - {{ .Values.persistence.accessMode }}
resources: resources:
requests: requests:
storage: {{ .Values.persistence.size | quote }} 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 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: {{ include "funkwhale.fullname" . }}-front name: {{ include "funkwhale.fullname" . }}
labels: labels:
app.kubernetes.io/name: {{ include "funkwhale.name" . }} app.kubernetes.io/name: {{ include "funkwhale.name" . }}
helm.sh/chart: {{ include "funkwhale.chart" . }} helm.sh/chart: {{ include "funkwhale.chart" . }}
@ -17,4 +18,4 @@ spec:
selector: selector:
app.kubernetes.io/name: {{ include "funkwhale.name" . }} app.kubernetes.io/name: {{ include "funkwhale.name" . }}
app.kubernetes.io/instance: {{ .Release.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. # Default values for funkwhale.
# This is a YAML-formatted file. # This is a YAML-formatted file.
# Declare variables to be passed into your templates. # Declare variables to be passed into your templates.
---
image: image:
repository: funkwhale/funkwhale repository: funkwhale/funkwhale
tag: 0.19.1 tag: 0.19.1
@ -10,6 +10,8 @@ image:
nameOverride: "" nameOverride: ""
fullnameOverride: "" fullnameOverride: ""
replicaCount: 1
service: service:
type: ClusterIP type: ClusterIP
port: 80 port: 80
@ -72,12 +74,14 @@ extraSecret: {}
persistence: persistence:
enabled: false enabled: false
# existingClaim: netbox-data
# storageClass: "-"
accessMode: ReadWriteMany
size: 1Gi size: 1Gi
storageClass: "-"
s3: s3:
enabled: false enabled: false
proxy: false proxy: true
accessKey: '' accessKey: ''
secretKey: '' secretKey: ''
@ -87,7 +91,7 @@ s3:
# url: http://s3.example.com # url: http://s3.example.com
api: api:
replicaCount: 1 # replicaCount: 1
# Additional mounts to add to the API pod # Additional mounts to add to the API pod
extraVolumeMounts: [] extraVolumeMounts: []
@ -96,6 +100,8 @@ api:
# readOnly: true # readOnly: true
# existingClaim: volume-claim # existingClaim: volume-claim
extraVolumes: []
resources: {} resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious # 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 # choice for the user. This also increases chances charts run on environments with little
@ -115,7 +121,7 @@ api:
affinity: {} affinity: {}
front: front:
replicaCount: 1 # replicaCount: 1
image: image:
repository: nginx repository: nginx
@ -129,6 +135,8 @@ front:
# readOnly: true # readOnly: true
# existingClaim: volume-claim # existingClaim: volume-claim
extraVolumes: []
resources: {} resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious # 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 # choice for the user. This also increases chances charts run on environments with little