diff --git a/helm/.helmignore b/helm/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/helm/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/helm/Chart.yaml b/helm/Chart.yaml new file mode 100644 index 0000000..2e70668 --- /dev/null +++ b/helm/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: librephotos +description: A Helm chart for Kubernetes +type: application +version: 0.1.0 +appVersion: "1.16.0" diff --git a/helm/templates/_helpers.tpl b/helm/templates/_helpers.tpl new file mode 100644 index 0000000..421119a --- /dev/null +++ b/helm/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "librephotos.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "librephotos.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "librephotos.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "librephotos.labels" -}} +helm.sh/chart: {{ include "librephotos.chart" . }} +{{ include "librephotos.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "librephotos.selectorLabels" -}} +app.kubernetes.io/name: {{ include "librephotos.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "librephotos.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "librephotos.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/helm/templates/backend.yaml b/helm/templates/backend.yaml new file mode 100644 index 0000000..b30309f --- /dev/null +++ b/helm/templates/backend.yaml @@ -0,0 +1,143 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }}-backend +spec: + {{- if not .Values.backend.autoscaling.enabled }} + replicas: {{ .Values.backend.replicaCount }} + {{- end }} + selector: + matchLabels: + app: {{ .Release.Name }}-backend + template: + metadata: + labels: + app: {{ .Release.Name }}-backend + {{- with .Values.backend.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.backend.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.backend.podSecurityContext }} + securityContext: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.backend.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.backend.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.backend.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: backend + image: {{ .Values.backend.image.repository }}:{{ .Values.backend.image.tag | default "2025w44" }} + {{- with .Values.backend.securityContext }} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + envFrom: + - configMapRef: + name: {{ .Release.Name }}-backend + - secretRef: + name: {{ .Release.Name }}-backend + - secretRef: + name: {{ .Release.Name }}-database + ports: + - name: backend + containerPort: 8001 + {{- with .Values.backend.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.backend.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.backend.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.backend.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + - name: proxy + image: {{ .Values.backend.proxy.image.repository }}:{{ .Values.backend.proxy.image.tag | default "2025w44" }} + {{- with .Values.backend.proxy.securityContext }} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.backend.proxy.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + ports: + - name: proxy + containerPort: 80 + {{- with .Values.backend.proxy.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.backend.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} +--- + +apiVersion: v1 +kind: Service +metadata: + name: backend # Service names can't be modified because of proxy nginx.conf file +spec: + selector: + app: {{ .Release.Name }}-backend + ports: + - name: http + port: 8001 + targetPort: backend + +--- + +apiVersion: v1 +kind: Service +metadata: + name: proxy # Service names can't be modified because of proxy nginx.conf file +spec: + selector: + app: {{ .Release.Name }}-backend + ports: + - name: http + port: 80 + targetPort: proxy +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }}-backend +data: + BACKEND_HOST: "{{ .Values.backend.config.backendHost }}" + ADMIN_EMAIL: "{{ .Values.backend.config.adminEmail }}" + ADMIN_USERNAME: "{{ .Values.backend.config.adminUsername }}" + DB_NAME: "{{ .Values.database.config.dbName }}" + DB_HOST: "{{ .Values.database.config.dbHost }}" + DB_PORT: "{{ .Values.database.config.dbPort }}" + WEB_CONCURRENCY: "{{ .Values.backend.config.webConcurrency }}" +--- +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Release.Name }}-backend +type: Opaque +data: + SECRET_KEY: {{ .Values.backend.secret.secretKey | default "changemechangemechangemechangeme" | b64enc }} + MAPBOX_API_KEY: {{ .Values.backend.secret.mapboxApiKey | default "" | b64enc }} + ADMIN_PASSWORD: {{ .Values.backend.secret.adminPassword | default "changeme" | b64enc }} diff --git a/helm/templates/database.yaml b/helm/templates/database.yaml new file mode 100644 index 0000000..30e63fc --- /dev/null +++ b/helm/templates/database.yaml @@ -0,0 +1,92 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }}-database +spec: + selector: + matchLabels: + app: {{ .Release.Name }}-database + template: + metadata: + labels: + app: {{ .Release.Name }}-database + {{- with .Values.database.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.database.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.database.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.database.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.database.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: postgres + image: {{ .Values.database.image.repository }}:{{ .Values.database.image.tag | default "15" }} + env: + - name: PGDATA + value: /var/lib/postgresql/data/pgdata + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + key: DB_PASS + name: {{ .Release.Name}}-database + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + key: DB_USER + name: {{ .Release.Name}}-database + - name: POSTGRES_DB + value: {{ .Values.database.config.dbName}} + {{- with .Values.database.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 10 }} + {{- end }} + {{- with .Values.database.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 10 }} + {{- end }} + ports: + - containerPort: 5432 + name: psql + {{- with .Values.database.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.database.securityContext }} + securityContext: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.database.volumes }} + volumes: + {{- toYaml . | nindent 6 }} + {{- end }} +--- +apiVersion: v1 +kind: Service +metadata: + name: database +spec: + ports: + - port: 5432 + name: psql + selector: + app: {{ .Release.Name }}-database +--- +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Release.Name}}-database +data: + DB_USER: {{ .Values.database.config.dbUser | default "librephotos" | b64enc }} + DB_PASS: {{ .Values.database.config.dbPass | default "changemechangemechangeme" |b64enc }} \ No newline at end of file diff --git a/helm/templates/frontend.yaml b/helm/templates/frontend.yaml new file mode 100644 index 0000000..fb5af0e --- /dev/null +++ b/helm/templates/frontend.yaml @@ -0,0 +1,70 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }}-frontend +spec: + selector: + matchLabels: + app: {{ .Release.Name }}-frontend + template: + metadata: + labels: + app: {{ .Release.Name }}-frontend + {{- with .Values.frontend.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.frontend.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{ - with .Values.frontend.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.frontend.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.frontend.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Release.Name }}-frontend + image: {{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag | default "2025w44" }} + ports: + - name: http + containerPort: 3000 + {{- with .Values.frontend.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.frontend.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.frontend.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.frontend.securityContext}} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.frontend.podSecurityContext }} + securityContext: + {{- toYaml . | nindent 8 }} + {{- end }} +--- + +apiVersion: v1 +kind: Service +metadata: + name: frontend # Service names can't be modified because of proxy nginx.conf file +spec: + ports: + - port: 3000 + name: http + selector: + app: {{ .Release.Name }}-frontend diff --git a/helm/templates/ingress.yaml b/helm/templates/ingress.yaml new file mode 100644 index 0000000..c40e0f4 --- /dev/null +++ b/helm/templates/ingress.yaml @@ -0,0 +1,26 @@ +{{- if .Values.ingress.enabled }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ .Release.Name }}-ingress + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + rules: + - host: "{{ .Values.ingress.host }}" + http: + paths: + - backend: + service: + name: proxy + port: + number: 80 + path: "/" + pathType: Prefix + tls: + - secretName: "{{ .Values.ingress.tls.secretName }}" + hosts: + - "{{ .Values.ingress.host }}" +{{- end }} \ No newline at end of file diff --git a/helm/templates/pvcs.yaml b/helm/templates/pvcs.yaml new file mode 100644 index 0000000..ed633ce --- /dev/null +++ b/helm/templates/pvcs.yaml @@ -0,0 +1,42 @@ +# This volume holds your photos. +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: photos +spec: + resources: + requests: + storage: {{ .Values.pvcs.photos.size }} + volumeMode: Filesystem + accessModes: + - ReadWriteOnce + +--- + +# This volume contains thumbnails. Setting it to 10-15% the size of "photos" is probably reasonable. +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: protected +spec: + resources: + requests: + storage: {{ .Values.pvcs.protected.size }} + volumeMode: Filesystem + accessModes: + - ReadWriteOnce + +--- + +# The postgres volume holds all the metadata. If it's 1% the size of "photos," you're probably fine. +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: postgres +spec: + resources: + requests: + storage: 1Gi + volumeMode: Filesystem + accessModes: + - ReadWriteOnce diff --git a/helm/values.yaml b/helm/values.yaml new file mode 100644 index 0000000..93ee91a --- /dev/null +++ b/helm/values.yaml @@ -0,0 +1,193 @@ +pvcs: + photos: + size: 30Gi + protected: + size: 3Gi + postgres: + size: 5Gi + +backend: + podAnnotations: {} + podLabels: {} + nodeSelector: {} + tolerations: [] + affinity: {} + + replicaCount: 1 + + image: + repository: reallibrephotos/librephotos + pullPolicy: IfNotPresent + tag: "2025w44" + + config: + backendHost: backend + adminEmail: somebody@example.com + adminUsername: admin + webConcurrency: 2 + + secret: + secretKey: changemechangemechangemechangeme + mapboxApiKey: changemechangemechangemechangeme + adminPassword: changeme + + podSecurityContext: + runAsUser: 65534 + runAsGroup: 65534 + fsGroup: 65534 + + securityContext: + readOnlyRootFilesystem: true + + resources: + limits: + memory: 3072Mi + requests: + cpu: 100m + memory: 2048Mi + + livenessProbe: {} + readinessProbe: {} + + volumes: + - name: photos + persistentVolumeClaim: + claimName: photos + - name: protected-media + persistentVolumeClaim: + claimName: protected + - name: logs + emptyDir: {} + - name: cache + emptyDir: {} + - name: backend-tmp + emptyDir: {} + - name: nginx-cache + emptyDir: {} + - name: proxy-var-run + emptyDir: {} + volumeMounts: + - name: photos + mountPath: /data + - name: protected-media + mountPath: /protected_media + - name: logs + mountPath: /logs + - name: cache + mountPath: /root/.cache + - name: backend-tmp + mountPath: /tmp + + autoscaling: + enabled: true + minReplicas: 1 + maxReplicas: 3 + targetMemoryUtilizationPercentage: 80 + + proxy: + resources: {} + image: + repository: reallibrephotos/librephotos-proxy + pullPolicy: IfNotPresent + tag: "2025w44" + volumeMounts: + - name: photos + mountPath: /data + - name: protected-media + mountPath: /protected_media + - name: nginx-cache + mountPath: /var/cache/nginx + - name: proxy-var-run + mountPath: /var/run + securityContext: + readOnlyRootFilesystem: true + +database: + podAnnotations: {} + podLabels: {} + nodeSelector: {} + tolerations: [] + affinity: {} + + config: + dbUser: librephotos + dbPass: changemechangemechangeme + dbName: librephotos + dbHost: database + dbPort: 5432 + + image: + repository: postgres + pullPolicy: IfNotPresent + tag: "15" + + livenessProbe: + exec: + command: + - pg_isready + - -h + - localhost + - -U + - librephotos + + readinessProbe: {} + + persistence: + enabled: true + accessModes: + - ReadWriteOnce + size: 10Gi + + resources: + requests: + memory: 512Mi + cpu: 250m + limits: + memory: 1024Mi + cpu: 500m + + volumes: + - name: data + persistentVolumeClaim: + claimName: postgres + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: data + + securityContext: + runAsUser: 999 + runAsGroup: 999 + fsGroup: 999 + +frontend: + podAnnotations: {} + podLabels: {} + nodeSelector: {} + tolerations: [] + affinity: {} + livenessProbe: {} + readinessProbe: {} + resources: {} + + image: + repository: reallibrephotos/librephotos-frontend + pullPolicy: IfNotPresent + tag: "2025w44" + + + podSecurityContext: + runAsUser: 65534 + runAsGroup: 65534 + fsGroup: 65534 + + securityContext: + readOnlyRootFilesystem: true + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + host: librephotos.your-domain.com + tls: + secretName: your-ssl-certificate