LibreTranslate/chart/templates/statefulset.yaml
Dominick Rivard ae7af14660 Add Helm Chart for LibreTranslate Deployment
Introduce a Helm chart to streamline the deployment and management of LibreTranslate within a Kubernetes cluster. The chart includes configurable parameters, persistent storage support, authentication, scalability features, health checks, and detailed documentation. See the PR for complete details.
2023-08-11 02:38:12 -04:00

344 lines
No EOL
14 KiB
YAML

apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "libretranslate.fullname" . }}
labels:
{{- include "libretranslate.labels" . | nindent 4 }}
{{- if .Values.annotations }}
annotations:
{{- toYaml .Values.annotations | nindent 4 }}
{{- end }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "libretranslate.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
{{- if .Values.podAnnotations }}
{{- toYaml .Values.podAnnotations | nindent 8 }}
{{- end }}
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
labels:
{{- include "libretranslate.selectorLabels" . | nindent 8 }}
spec:
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 8 }}
{{- end }}
{{- if .Values.securityContext }}
# forces the mount of the volumes to be mounted as libretranslate user and group
# and set permissions to libretranslate:libretranslate
securityContext:
{{- toYaml .Values.securityContext | nindent 8 }}
{{- end }}
{{- if .Values.persistence.enabled }}
initContainers:
- name: volume-permissions-and-pre-install-models
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
command:
- /bin/bash
- -c
- |
mkdir -p /home/libretranslate/.local/share/argos-translate/packages
chown -R 1032:1032 /home/libretranslate/.local /app/db
if [ ! "$(ls -A /home/libretranslate/.local/share/argos-translate/packages)" ]; then
echo "Installing models... this can take quite a while depending on your internet connection."
/app/venv/bin/python /app/scripts/install_models.py --load_only_lang_codes {{ .Values.appConfig.loadOnly | quote }}
else
echo "The models directory is not empty, skipping model installation."
fi
volumeMounts:
- name: models-volume
mountPath: /home/libretranslate/.local/share/argos-translate
- name: db-volume
mountPath: {{ .Values.appConfig.apiKeysDbPathMount }}
{{- if .Values.initContainerSecurityContext }}
securityContext:
# forces the mount of the volumes to be mounted as libretranslate user and group
# and set permissions to libretranslate:libretranslate
{{- toYaml .Values.initContainerSecurityContext | nindent 12 }}
{{- end }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
securityContext:
{{- if .Values.podSecurityContext }}
# forces the mount of the volumes to be mounted as libretranslate user and group
# and set permissions to libretranslate:libretranslate
{{- toYaml .Values.podSecurityContext | nindent 12 }}
{{- end }}
allowPrivilegeEscalation: false
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
env:
{{- if and (.Values.appSettings.debug) (ne .Values.appSettings.debug "") }}
- name: LT_DEBUG
valueFrom:
configMapKeyRef:
name: libretranslate-appsettings
key: debug
{{- end }}
{{- if and (.Values.appSettings.ssl) (ne .Values.appSettings.ssl "") }}
- name: LT_SSL
valueFrom:
configMapKeyRef:
name: libretranslate-appsettings
key: ssl
{{- end }}
{{- if and (.Values.appSettings.apiKeys) (ne .Values.appSettings.apiKeys "") }}
- name: LT_API_KEYS
valueFrom:
configMapKeyRef:
name: libretranslate-appsettings
key: apiKeys
{{- end }}
{{- if and (.Values.appSettings.requireApiKeyOrigin) (ne .Values.appSettings.requireApiKeyOrigin "") }}
- name: LT_REQUIRE_API_KEY_ORIGIN
valueFrom:
configMapKeyRef:
name: libretranslate-appsettings
key: requireApiKeyOrigin
{{- end }}
{{- if and (.Values.appSettings.requireApiKeySecret) (ne .Values.appSettings.requireApiKeySecret "") }}
- name: LT_REQUIRE_API_KEY_SECRET
valueFrom:
configMapKeyRef:
name: libretranslate-appsettings
key: requireApiKeySecret
{{- end }}
{{- if and (.Values.appSettings.suggestions) (ne .Values.appSettings.suggestions "") }}
- name: LT_SUGGESTIONS
valueFrom:
configMapKeyRef:
name: libretranslate-appsettings
key: suggestions
{{- end }}
{{- if and (.Values.appSettings.disableFilesTranslation) (ne .Values.appSettings.disableFilesTranslation "") }}
- name: LT_DISABLE_FILES_TRANSLATION
valueFrom:
configMapKeyRef:
name: libretranslate-appsettings
key: disableFilesTranslation
{{- end }}
{{- if and (.Values.appSettings.disableWebUi) (ne .Values.appSettings.disableWebUi "") }}
- name: LT_DISABLE_WEB_UI
valueFrom:
configMapKeyRef:
name: libretranslate-appsettings
key: disableWebUi
{{- end }}
{{- if and (.Values.appSettings.updateModels) (ne .Values.appSettings.updateModels "") }}
- name: LT_UPDATE_MODELS
valueFrom:
configMapKeyRef:
name: libretranslate-appsettings
key: updateModels
{{- end }}
{{- if and (.Values.appSettings.metrics) (ne .Values.appSettings.metrics "") }}
- name: LT_METRICS
valueFrom:
configMapKeyRef:
name: libretranslate-appsettings
key: metrics
{{- end }}
{{- if and (.Values.appConfig.host) (ne .Values.appConfig.host "") }}
- name: LT_HOST
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: host
{{- end }}
{{- if and (.Values.appSettings.port) (ne .Values.appSettings.port "") }}
- name: LT_PORT
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: port
{{- end }}
{{- if and (.Values.appConfig.charLimit) (ne .Values.appConfig.charLimit "") }}
- name: LT_CHAR_LIMIT
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: charLimit
{{- end }}
{{- if and (.Values.appConfig.reqLimit) (ne .Values.appConfig.reqLimit "") }}
- name: LT_REQ_LIMIT
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: reqLimit
{{- end }}
{{- if and (.Values.appConfig.reqLimitStorage) (ne .Values.appConfig.reqLimitStorage "") }}
- name: LT_REQ_LIMIT_STORAGE
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: reqLimitStorage
{{- end }}
{{- if and (.Values.appConfig.batchLimit) (ne .Values.appConfig.batchLimit "") }}
- name: LT_BATCH_LIMIT
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: batchLimit
{{- end }}
{{- if and (.Values.appConfig.gaId) (ne .Values.appConfig.gaId "") }}
- name: LT_GA_ID
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: gaId
{{- end }}
{{- if and (.Values.appConfig.frontendLanguageSource) (ne .Values.appConfig.frontendLanguageSource "") }}
- name: LT_FRONTEND_LANGUAGE_SOURCE
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: frontendLanguageSource
{{- end }}
{{- if and (.Values.appConfig.frontendLanguageTarget) (ne .Values.appConfig.frontendLanguageTarget "") }}
- name: LT_FRONTEND_LANGUAGE_TARGET
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: frontendLanguageTarget
{{- end }}
{{- if and (.Values.appConfig.frontendTimeout) (ne .Values.appConfig.frontendTimeout "") }}
- name: LT_FRONTEND_TIMEOUT
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: frontendTimeout
{{- end }}
{{- if and (.Values.appSettings.apiKeysDbPath) (ne .Values.appSettings.apiKeysDbPath "") }}
- name: LT_API_KEYS_DB_PATH
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: apiKeysDbPath
{{- end }}
{{- if and (.Values.appSettings.apiKeysRemote) (ne .Values.appSettings.apiKeysRemote "") }}
- name: LT_API_KEYS_REMOTE
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: apiKeysRemote
{{- end }}
{{- if and (.Values.appConfig.getApiKeyLink) (ne .Values.appConfig.getApiKeyLink "") }}
- name: LT_GET_API_KEY_LINK
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: getApiKeyLink
{{- end }}
{{- if and (.Values.appConfig.sharedStorage) (ne .Values.appConfig.sharedStorage "") }}
- name: LT_SHARED_STORAGE
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: sharedStorage
{{- end }}
{{- if and (.Values.appConfig.loadOnly) (ne .Values.appConfig.loadOnly "") }}
- name: LT_LOAD_ONLY
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: loadOnly
{{- end }}
{{- if and (.Values.appConfig.threads) (ne .Values.appConfig.threads "") }}
- name: LT_THREADS
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: threads
{{- end }}
{{- if and (.Values.appSettings.metricsAuthToken) (ne .Values.appSettings.metricsAuthToken "") }}
- name: LT_METRICS_AUTH_TOKEN
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: metricsAuthToken
{{- end }}
{{- if and (.Values.appConfig.urlPrefix) (ne .Values.appConfig.urlPrefix "") }}
- name: LT_URL_PREFIX
valueFrom:
configMapKeyRef:
name: libretranslate-config
key: urlPrefix
{{- end }}
{{- if .Values.persistence.enabled }}
volumeMounts:
- name: db-volume
mountPath: {{ .Values.appConfig.apiKeysDbPathMount }}
- name: models-volume
mountPath: /home/libretranslate/.local/share/argos-translate
{{- end }}
{{- if and .Values.persistence.enabled (or (eq .Values.persistence.models.accessMode "ReadWriteMany") (eq .Values.persistence.db.accessMode "ReadWriteMany")) }}
volumes:
{{- if eq .Values.persistence.db.accessMode "ReadWriteMany" }}
- name: db-volume
persistentVolumeClaim:
claimName: db-volume
{{- end }}
{{- if eq .Values.persistence.models.accessMode "ReadWriteMany" }}
- name: models-volume
persistentVolumeClaim:
claimName: models-volume
{{- end }}
{{- end }}
{{- if .Values.tolerations }}
tolerations:
{{- toYaml .Values.tolerations | nindent 6 }}
{{- end }}
{{- if and .Values.persistence.enabled (or (eq .Values.persistence.models.accessMode "ReadWriteOnce") (eq .Values.persistence.db.accessMode "ReadWriteOnce")) }}
# still in beta, but this will allow us to delete the volumes when the statefulset is scaled down
persistentVolumeClaimRetentionPolicy:
whenDeleted: Retain
whenScaled: Delete
volumeClaimTemplates:
{{- if eq .Values.persistence.models.accessMode "ReadWriteOnce" }}
- metadata:
name: models-volume
labels:
{{- include "libretranslate.labels" . | nindent 8 }}
spec:
accessModes:
- {{ .Values.persistence.models.accessMode }}
resources:
requests:
storage: {{ .Values.persistence.models.size }}
{{- if .Values.persistence.models.storageClass }}
storageClassName: {{ .Values.persistence.models.storageClass | quote }}
{{- end }}
{{- end }}
{{- if eq .Values.persistence.db.accessMode "ReadWriteOnce" }}
- metadata:
name: db-volume
labels:
{{- include "libretranslate.labels" . | nindent 8 }}
spec:
accessModes:
- {{ .Values.persistence.db.accessMode }}
resources:
requests:
storage: {{ .Values.persistence.db.size }}
{{- if .Values.persistence.db.storageClass }}
storageClassName: {{ .Values.persistence.db.storageClass | quote }}
{{- end }}
{{- end }}
{{- end }}