Skip to content

Commit 57f6020

Browse files
authored
Merge pull request #37 from holysoles/scale_backend_seperate_from_frontend
Add support for separate Horizon deployment
2 parents 3684161 + eb8aefb commit 57f6020

File tree

8 files changed

+290
-6
lines changed

8 files changed

+290
-6
lines changed

charts/pixelfed/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.14.5
18+
version: 0.15.0
1919

2020
# This is the version number of the application being deployed.
2121
# renovate:image=ghcr.io/mattlqx/docker-pixelfed

charts/pixelfed/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pixelfed
22

3-
![Version: 0.14.5](https://img.shields.io/badge/Version-0.14.5-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.12.4-nginx](https://img.shields.io/badge/AppVersion-v0.12.4--nginx-informational?style=flat-square)
3+
![Version: 0.15.0](https://img.shields.io/badge/Version-0.15.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.12.4-nginx](https://img.shields.io/badge/AppVersion-v0.12.4--nginx-informational?style=flat-square)
44

55
A Helm chart for deploying Pixelfed on Kubernetes
66

@@ -105,6 +105,8 @@ A Helm chart for deploying Pixelfed on Kubernetes
105105
| pixelfed.force_https_urls | bool | `true` | Force https url generation |
106106
| pixelfed.horizon.dark_mode | bool | `false` | darkmode for the web interface in the admin panel |
107107
| pixelfed.horizon.prefix | string | `"horizon-"` | prefix will be used when storing all Horizon data in Redis |
108+
| pixelfed.horizon.replicas | int | `1` | Number of replicas for the Horizon deployment when running separately. Ignored if autoscaling is enabled. |
109+
| pixelfed.horizon.separate_deployment | bool | `false` | Enable running Laravel Horizon in a separate deployment. Allow to scale the backend queue workers independently. |
108110
| pixelfed.image_driver | string | `"gd"` | library to process images. options: "gd" (default), "imagick" |
109111
| pixelfed.image_quality | int | `80` | Set the image optimization quality, between 1-100. Lower uses less space, higher more quality |
110112
| pixelfed.instance.contact_email | string | `""` | The public contact email for your server |

charts/pixelfed/templates/_helpers.tpl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ Common labels
3535
*/}}
3636
{{- define "pixelfed.labels" -}}
3737
helm.sh/chart: {{ include "pixelfed.chart" . }}
38-
{{ include "pixelfed.selectorLabels" . }}
3938
{{- if .Chart.AppVersion }}
4039
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
4140
{{- end }}
@@ -45,9 +44,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
4544
{{/*
4645
Selector labels
4746
*/}}
48-
{{- define "pixelfed.selectorLabels" -}}
47+
{{- define "pixelfed.web.selectorLabels" -}}
4948
app.kubernetes.io/name: {{ include "pixelfed.name" . }}
5049
app.kubernetes.io/instance: {{ .Release.Name }}
50+
app.kubernetes.io/component: web
51+
{{- end }}
52+
53+
{{/*
54+
Horizon selector labels
55+
*/}}
56+
{{- define "pixelfed.horizon.selectorLabels" -}}
57+
app.kubernetes.io/component: horizon
5158
{{- end }}
5259

5360
{{/*

charts/pixelfed/templates/deployment.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spec:
1010
{{- end }}
1111
selector:
1212
matchLabels:
13-
{{- include "pixelfed.selectorLabels" . | nindent 6 }}
13+
{{- include "pixelfed.web.selectorLabels" . | nindent 6 }}
1414
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
1515
template:
1616
metadata:
@@ -22,6 +22,7 @@ spec:
2222
{{- toYaml . | nindent 8 }}
2323
{{- end }}
2424
labels:
25+
{{- include "pixelfed.web.selectorLabels" . | nindent 8 }}
2526
{{- include "pixelfed.labels" . | nindent 8 }}
2627
{{- with .Values.podLabels }}
2728
{{- toYaml . | nindent 8 }}
@@ -67,6 +68,10 @@ spec:
6768
{{- toYaml . | nindent 12 }}
6869
{{- end }}
6970

71+
# Run horizon inside this pod dependent upon the separate_deployment flag
72+
- name: ENABLE_HORIZON
73+
value: "{{ not .Values.pixelfed.horizon.separate_deployment }}"
74+
7075
# pixelfed app key
7176
- name: APP_KEY
7277
valueFrom:
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
{{- if .Values.pixelfed.horizon.separate_deployment }}
2+
---
3+
apiVersion: apps/v1
4+
kind: Deployment
5+
metadata:
6+
name: {{ include "pixelfed.fullname" . }}-backend
7+
labels:
8+
{{- include "pixelfed.labels" . | nindent 4 }}
9+
spec:
10+
{{- if not .Values.autoscaling.enabled }}
11+
replicas: {{ .Values.pixelfed.horizon.replicas }}
12+
{{- end }}
13+
selector:
14+
matchLabels:
15+
{{- include "pixelfed.horizon.selectorLabels" . | nindent 6 }}
16+
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
17+
template:
18+
metadata:
19+
annotations:
20+
# reload deployment if config files change
21+
php-config-hash: {{ toJson .Values.phpConfigs | sha256sum }}
22+
checksum/config: {{ include (print $.Template.BasePath "/configmap_env.yaml") . | sha256sum }}
23+
{{- with .Values.podAnnotations }}
24+
{{- toYaml . | nindent 8 }}
25+
{{- end }}
26+
labels:
27+
{{- include "pixelfed.horizon.selectorLabels" . | nindent 8 }}
28+
{{- include "pixelfed.labels" . | nindent 8 }}
29+
{{- with .Values.podLabels }}
30+
{{- toYaml . | nindent 8 }}
31+
{{- end }}
32+
spec:
33+
{{- with .Values.imagePullSecrets }}
34+
imagePullSecrets:
35+
{{- toYaml . | nindent 8 }}
36+
{{- end }}
37+
serviceAccountName: {{ include "pixelfed.serviceAccountName" . }}
38+
{{- with .Values.podSecurityContext }}
39+
securityContext:
40+
{{- toYaml . | nindent 8 }}
41+
{{- end }}
42+
{{- with .Values.extraInitContainers }}
43+
initContainers:
44+
{{- toYaml . | nindent 8 }}
45+
{{- end }}
46+
containers:
47+
- name: {{ .Chart.Name }}-backend
48+
{{- with .Values.securityContext }}
49+
securityContext:
50+
{{- toYaml . | nindent 12 }}
51+
{{- end }}
52+
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
53+
imagePullPolicy: {{ .Values.image.pullPolicy }}
54+
command: ["php"]
55+
args: ["artisan", "horizon"]
56+
envFrom:
57+
{{- with .Values.extraEnvFrom }}
58+
{{- toYaml . | nindent 12 }}
59+
{{- end }}
60+
- configMapRef:
61+
name: {{ include "pixelfed.fullname" . }}-env
62+
env:
63+
{{- with .Values.extraEnv }}
64+
{{- toYaml . | nindent 12 }}
65+
{{- end }}
66+
67+
# pixelfed app key
68+
- name: APP_KEY
69+
valueFrom:
70+
secretKeyRef:
71+
{{- if and .Values.pixelfed.app.existingSecret .Values.pixelfed.app.existingSecretKey }}
72+
name: {{ .Values.pixelfed.app.existingSecret }}
73+
key: {{ .Values.pixelfed.app.existingSecretKey }}
74+
{{- else }}
75+
name: {{ include "pixelfed.fullname" . }}-app-key
76+
key: key
77+
{{- end }}
78+
79+
# valkey AKA redis
80+
{{- if and .Values.externalValkey.enabled .Values.externalValkey.existingSecretKeys.host }}
81+
- name: REDIS_HOST
82+
valueFrom:
83+
secretKeyRef:
84+
{{- if and .Values.externalValkey.existingSecret .Values.externalValkey.existingSecretKeys.host }}
85+
name: {{ .Values.externalValkey.existingSecret }}
86+
key: {{ .Values.externalValkey.existingSecretKeys.host }}
87+
{{- else }}
88+
name: {{ include "pixelfed.fullname" . }}-valkey
89+
key: host
90+
{{- end }}
91+
{{- end }}
92+
93+
{{- if and .Values.externalValkey.enabled .Values.externalValkey.existingSecret .Values.externalValkey.existingSecretKeys.port }}
94+
- name: REDIS_PORT
95+
valueFrom:
96+
secretKeyRef:
97+
{{- if and .Values.externalValkey.existingSecret .Values.externalValkey.existingSecretKeys.port }}
98+
name: {{ .Values.externalValkey.existingSecret }}
99+
key: {{ .Values.externalValkey.existingSecretKeys.port }}
100+
{{- else }}
101+
name: {{ include "pixelfed.fullname" . }}-valkey
102+
key: port
103+
{{- end }}
104+
{{- end }}
105+
106+
- name: REDIS_PASSWORD
107+
valueFrom:
108+
secretKeyRef:
109+
{{- if and .Values.externalValkey.enabled .Values.externalValkey.existingSecret }}
110+
name: {{ .Values.externalValkey.existingSecret }}
111+
key: {{ .Values.externalValkey.existingSecretKeys.password }}
112+
{{- else if and .Values.externalValkey.enabled (not .Values.externalValkey.existingSecret) }}
113+
name: {{ include "pixelfed.fullname" . }}-valkey
114+
key: password
115+
{{- else if .Values.valkey.auth.existingSecret }}
116+
name: {{ .Values.valkey.auth.existingSecret }}
117+
key: password
118+
{{- else }}
119+
name: {{ .Values.valkey.fullnameOverride }}
120+
key: valkey-password
121+
{{- end }}
122+
123+
# database configuration
124+
{{- if .Values.externalDatabase.enabled }}
125+
- name: DB_HOST
126+
valueFrom:
127+
secretKeyRef:
128+
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret .Values.externalDatabase.existingSecretKeys.host }}
129+
name: {{ .Values.externalDatabase.existingSecret }}
130+
key: {{ .Values.externalDatabase.existingSecretKeys.host }}
131+
{{- else if and .Values.externalDatabase.enabled (not .Values.externalDatabase.existingSecretKeys.host) }}
132+
name: {{ include "pixelfed.fullname" . }}-database
133+
key: host
134+
{{- end }}
135+
{{- end }}
136+
137+
{{- if .Values.externalDatabase.enabled }}
138+
- name: DB_USERNAME
139+
valueFrom:
140+
secretKeyRef:
141+
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret .Values.externalDatabase.existingSecretKeys.username }}
142+
name: {{ .Values.externalDatabase.existingSecret }}
143+
key: {{ .Values.externalDatabase.existingSecretKeys.username }}
144+
{{- else if and .Values.externalDatabase.enabled (not .Values.externalDatabase.existingSecretKeys.username) }}
145+
name: {{ include "pixelfed.fullname" . }}-database
146+
key: username
147+
{{- end }}
148+
{{- end }}
149+
150+
{{- if .Values.externalDatabase.enabled }}
151+
- name: DB_DATABASE
152+
valueFrom:
153+
secretKeyRef:
154+
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret .Values.externalDatabase.existingSecretKeys.database }}
155+
name: {{ .Values.externalDatabase.existingSecret }}
156+
key: {{ .Values.externalDatabase.existingSecretKeys.database }}
157+
{{- else if and .Values.externalDatabase.enabled (not .Values.externalDatabase.existingSecretKeys.database) }}
158+
name: {{ include "pixelfed.fullname" . }}-database
159+
key: database
160+
{{- end }}
161+
{{- end }}
162+
163+
{{- if .Values.externalDatabase.enabled }}
164+
- name: DB_PORT
165+
valueFrom:
166+
secretKeyRef:
167+
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret .Values.externalDatabase.existingSecretKeys.port }}
168+
name: {{ .Values.externalDatabase.existingSecret }}
169+
key: {{ .Values.externalDatabase.existingSecretKeys.port }}
170+
{{- else if and .Values.externalDatabase.enabled (not .Values.externalDatabase.existingSecretKeys.port) }}
171+
name: {{ include "pixelfed.fullname" . }}-database
172+
key: port
173+
{{- end }}
174+
{{- end }}
175+
176+
- name: DB_PASSWORD
177+
{{- if and .Values.externalDatabase.enabled (not .Values.externalDatabase.existingSecret) }}
178+
value: {{ .Values.externalDatabase.password }}
179+
{{- else }}
180+
valueFrom:
181+
secretKeyRef:
182+
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret }}
183+
name: {{ .Values.externalDatabase.existingSecret }}
184+
key: {{ .Values.externalDatabase.existingSecretKeys.password }}
185+
{{- else if .Values.postgresql.auth.existingSecret }}
186+
name: {{ .Values.postgresql.auth.existingSecret }}
187+
key: postgres-password
188+
{{- else }}
189+
name: {{ .Values.postgresql.fullnameOverride }}
190+
key: postgres-password
191+
{{- end }}
192+
{{- end }}
193+
194+
{{- with .Values.resources }}
195+
resources:
196+
{{- toYaml . | nindent 12 }}
197+
{{- end }}
198+
199+
{{- if or .Values.extraVolumeMounts .Values.phpConfigs }}
200+
volumeMounts:
201+
{{- with .Values.extraVolumeMounts }}
202+
{{- toYaml . | nindent 12 }}
203+
{{- end }}
204+
{{- range $key, $value := .Values.phpConfigs }}
205+
- name: phpconfig
206+
mountPath: {{ print "/usr/local/etc/php-fpm.d/%s" $key | quote }}
207+
subPath: {{ $key }}
208+
{{- end }}
209+
{{- end }}{{/* end volumeMounts */}}
210+
211+
{{- if or .Values.phpConfigs .Values.extraVolumes }}
212+
volumes:
213+
{{- with .Values.extraVolumes }}
214+
{{- toYaml . | nindent 8 }}
215+
{{- end }}
216+
{{- if .Values.phpConfigs }}
217+
- name: phpconfig
218+
configMap:
219+
name: {{ template "pixelfed.fullname" . }}-phpconfig
220+
{{- end }}
221+
{{- end }}
222+
{{- with .Values.nodeSelector }}
223+
nodeSelector:
224+
{{- toYaml . | nindent 8 }}
225+
{{- end }}
226+
{{- with .Values.affinity }}
227+
affinity:
228+
{{- toYaml . | nindent 8 }}
229+
{{- end }}
230+
{{- with .Values.tolerations }}
231+
tolerations:
232+
{{- toYaml . | nindent 8 }}
233+
{{- end }}
234+
{{- end }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- if and .Values.autoscaling.enabled .Values.pixelfed.horizon.separate_deployment }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "pixelfed.fullname" . }}-backend
6+
labels:
7+
{{- include "pixelfed.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "pixelfed.fullname" . }}-backend
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
target:
21+
type: Utilization
22+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
23+
{{- end }}
24+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
25+
- type: Resource
26+
resource:
27+
name: memory
28+
target:
29+
type: Utilization
30+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
31+
{{- end }}
32+
{{- end }}

charts/pixelfed/templates/service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ spec:
1212
protocol: TCP
1313
name: http
1414
selector:
15-
{{- include "pixelfed.selectorLabels" . | nindent 4 }}
15+
{{- include "pixelfed.web.selectorLabels" . | nindent 4 }}

charts/pixelfed/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ pixelfed:
335335
prefix: "horizon-"
336336
# -- darkmode for the web interface in the admin panel
337337
dark_mode: false
338+
# -- Enable running Laravel Horizon in a separate deployment. Allow to scale the backend queue workers independently.
339+
separate_deployment: false
340+
# -- Number of replicas for the Horizon deployment when running separately. Ignored if autoscaling is enabled.
341+
replicas: 1
338342

339343
# app specific settings
340344
app:

0 commit comments

Comments
 (0)