Add support for separate Horizon deployment

This commit is contained in:
holysoles
2025-01-22 20:06:21 -06:00
parent cf128bf9d4
commit 5fb13fe030
7 changed files with 288 additions and 6 deletions
+9 -2
View File
@@ -35,7 +35,6 @@ Common labels
*/}}
{{- define "pixelfed.labels" -}}
helm.sh/chart: {{ include "pixelfed.chart" . }}
{{ include "pixelfed.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
@@ -45,9 +44,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{/*
Selector labels
*/}}
{{- define "pixelfed.selectorLabels" -}}
{{- define "pixelfed.web.selectorLabels" -}}
app.kubernetes.io/name: {{ include "pixelfed.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: web
{{- end }}
{{/*
Horizon selector labels
*/}}
{{- define "pixelfed.horizon.selectorLabels" -}}
app.kubernetes.io/component: horizon
{{- end }}
{{/*
+6 -1
View File
@@ -10,7 +10,7 @@ spec:
{{- end }}
selector:
matchLabels:
{{- include "pixelfed.selectorLabels" . | nindent 6 }}
{{- include "pixelfed.web.selectorLabels" . | nindent 6 }}
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
template:
metadata:
@@ -22,6 +22,7 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "pixelfed.web.selectorLabels" . | nindent 8 }}
{{- include "pixelfed.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
@@ -67,6 +68,10 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
# Run horizon inside this pod dependent upon the separate_deployment flag
- name: ENABLE_HORIZON
value: "{{ not .Values.pixelfed.horizon.separate_deployment }}"
# pixelfed app key
- name: APP_KEY
valueFrom:
@@ -0,0 +1,234 @@
{{- if .Values.pixelfed.horizon.separate_deployment }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "pixelfed.fullname" . }}-backend
labels:
{{- include "pixelfed.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.pixelfed.horizon.replicas }}
{{- end }}
selector:
matchLabels:
{{- include "pixelfed.horizon.selectorLabels" . | nindent 6 }}
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
template:
metadata:
annotations:
# reload deployment if config files change
php-config-hash: {{ toJson .Values.phpConfigs | sha256sum }}
checksum/config: {{ include (print $.Template.BasePath "/configmap_env.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "pixelfed.horizon.selectorLabels" . | nindent 8 }}
{{- include "pixelfed.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "pixelfed.serviceAccountName" . }}
{{- with .Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.extraInitContainers }}
initContainers:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}-backend
{{- with .Values.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["php"]
args: ["artisan", "horizon"]
envFrom:
{{- with .Values.extraEnvFrom }}
{{- toYaml . | nindent 12 }}
{{- end }}
- configMapRef:
name: {{ include "pixelfed.fullname" . }}-env
env:
{{- with .Values.extraEnv }}
{{- toYaml . | nindent 12 }}
{{- end }}
# pixelfed app key
- name: APP_KEY
valueFrom:
secretKeyRef:
{{- if and .Values.pixelfed.app.existingSecret .Values.pixelfed.app.existingSecretKey }}
name: {{ .Values.pixelfed.app.existingSecret }}
key: {{ .Values.pixelfed.app.existingSecretKey }}
{{- else }}
name: {{ include "pixelfed.fullname" . }}-app-key
key: key
{{- end }}
# valkey AKA redis
{{- if and .Values.externalValkey.enabled .Values.externalValkey.existingSecretKeys.host }}
- name: REDIS_HOST
valueFrom:
secretKeyRef:
{{- if and .Values.externalValkey.existingSecret .Values.externalValkey.existingSecretKeys.host }}
name: {{ .Values.externalValkey.existingSecret }}
key: {{ .Values.externalValkey.existingSecretKeys.host }}
{{- else }}
name: {{ include "pixelfed.fullname" . }}-valkey
key: host
{{- end }}
{{- end }}
{{- if and .Values.externalValkey.enabled .Values.externalValkey.existingSecret .Values.externalValkey.existingSecretKeys.port }}
- name: REDIS_PORT
valueFrom:
secretKeyRef:
{{- if and .Values.externalValkey.existingSecret .Values.externalValkey.existingSecretKeys.port }}
name: {{ .Values.externalValkey.existingSecret }}
key: {{ .Values.externalValkey.existingSecretKeys.port }}
{{- else }}
name: {{ include "pixelfed.fullname" . }}-valkey
key: port
{{- end }}
{{- end }}
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
{{- if and .Values.externalValkey.enabled .Values.externalValkey.existingSecret }}
name: {{ .Values.externalValkey.existingSecret }}
key: {{ .Values.externalValkey.existingSecretKeys.password }}
{{- else if and .Values.externalValkey.enabled (not .Values.externalValkey.existingSecret) }}
name: {{ include "pixelfed.fullname" . }}-valkey
key: password
{{- else if .Values.valkey.auth.existingSecret }}
name: {{ .Values.valkey.auth.existingSecret }}
key: password
{{- else }}
name: {{ .Values.valkey.fullnameOverride }}
key: valkey-password
{{- end }}
# database configuration
{{- if .Values.externalDatabase.enabled }}
- name: DB_HOST
valueFrom:
secretKeyRef:
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret .Values.externalDatabase.existingSecretKeys.host }}
name: {{ .Values.externalDatabase.existingSecret }}
key: {{ .Values.externalDatabase.existingSecretKeys.host }}
{{- else if and .Values.externalDatabase.enabled (not .Values.externalDatabase.existingSecretKeys.host) }}
name: {{ include "pixelfed.fullname" . }}-database
key: host
{{- end }}
{{- end }}
{{- if .Values.externalDatabase.enabled }}
- name: DB_USERNAME
valueFrom:
secretKeyRef:
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret .Values.externalDatabase.existingSecretKeys.username }}
name: {{ .Values.externalDatabase.existingSecret }}
key: {{ .Values.externalDatabase.existingSecretKeys.username }}
{{- else if and .Values.externalDatabase.enabled (not .Values.externalDatabase.existingSecretKeys.username) }}
name: {{ include "pixelfed.fullname" . }}-database
key: username
{{- end }}
{{- end }}
{{- if .Values.externalDatabase.enabled }}
- name: DB_DATABASE
valueFrom:
secretKeyRef:
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret .Values.externalDatabase.existingSecretKeys.database }}
name: {{ .Values.externalDatabase.existingSecret }}
key: {{ .Values.externalDatabase.existingSecretKeys.database }}
{{- else if and .Values.externalDatabase.enabled (not .Values.externalDatabase.existingSecretKeys.database) }}
name: {{ include "pixelfed.fullname" . }}-database
key: database
{{- end }}
{{- end }}
{{- if .Values.externalDatabase.enabled }}
- name: DB_PORT
valueFrom:
secretKeyRef:
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret .Values.externalDatabase.existingSecretKeys.port }}
name: {{ .Values.externalDatabase.existingSecret }}
key: {{ .Values.externalDatabase.existingSecretKeys.port }}
{{- else if and .Values.externalDatabase.enabled (not .Values.externalDatabase.existingSecretKeys.port) }}
name: {{ include "pixelfed.fullname" . }}-database
key: port
{{- end }}
{{- end }}
- name: DB_PASSWORD
{{- if and .Values.externalDatabase.enabled (not .Values.externalDatabase.existingSecret) }}
value: {{ .Values.externalDatabase.password }}
{{- else }}
valueFrom:
secretKeyRef:
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret }}
name: {{ .Values.externalDatabase.existingSecret }}
key: {{ .Values.externalDatabase.existingSecretKeys.password }}
{{- else if .Values.postgresql.auth.existingSecret }}
name: {{ .Values.postgresql.auth.existingSecret }}
key: postgres-password
{{- else }}
name: {{ .Values.postgresql.fullnameOverride }}
key: postgres-password
{{- end }}
{{- end }}
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if or .Values.extraVolumeMounts .Values.phpConfigs }}
volumeMounts:
{{- with .Values.extraVolumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- range $key, $value := .Values.phpConfigs }}
- name: phpconfig
mountPath: {{ print "/usr/local/etc/php-fpm.d/%s" $key | quote }}
subPath: {{ $key }}
{{- end }}
{{- end }}{{/* end volumeMounts */}}
{{- if or .Values.phpConfigs .Values.extraVolumes }}
volumes:
{{- with .Values.extraVolumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.phpConfigs }}
- name: phpconfig
configMap:
name: {{ template "pixelfed.fullname" . }}-phpconfig
{{- end }}
{{- end }}
{{- 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 }}
@@ -0,0 +1,32 @@
{{- if and .Values.autoscaling.enabled .Values.pixelfed.horizon.separate_deployment }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "pixelfed.fullname" . }}-backend
labels:
{{- include "pixelfed.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "pixelfed.fullname" . }}-backend
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
+1 -1
View File
@@ -12,4 +12,4 @@ spec:
protocol: TCP
name: http
selector:
{{- include "pixelfed.selectorLabels" . | nindent 4 }}
{{- include "pixelfed.web.selectorLabels" . | nindent 4 }}