chore: Add initial Helm chart for MariaDB with templates and values

This commit is contained in:
sha
2026-06-10 02:47:02 +03:00
parent 4868f77ed1
commit 93352adfdc
7 changed files with 257 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
{{- define "mariadb.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- define "mariadb.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 }}
{{- define "mariadb.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- define "mariadb.labels" -}}
helm.sh/chart: {{ include "mariadb.chart" . }}
{{ include "mariadb.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{- define "mariadb.selectorLabels" -}}
app.kubernetes.io/name: {{ include "mariadb.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
+45
View File
@@ -0,0 +1,45 @@
{{- if .Values.backup.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "mariadb.fullname" . }}-backup
labels:
{{- include "mariadb.labels" . | nindent 4 }}
spec:
schedule: {{ .Values.backup.schedule | quote }}
jobTemplate:
spec:
template:
spec:
containers:
- name: mariadb-backup
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
command:
- /bin/sh
- -c
- |
mariadb-dump -h {{ include "mariadb.fullname" . }} -u root -p"$MARIADB_ROOT_PASSWORD" --all-databases \
| gzip > /backup/mariadb-all-$(date +%Y%m%d-%H%M%S).sql.gz
find /backup -name "mariadb-all-*.sql.gz" -mtime +$RETENTION_DAYS -delete
env:
- name: MARIADB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.auth.existingSecret }}
key: {{ .Values.auth.rootPasswordKey }}
- name: RETENTION_DAYS
value: {{ .Values.backup.retentionDays | quote }}
volumeMounts:
- name: backup-storage
mountPath: /backup
volumes:
- name: backup-storage
hostPath:
path: {{ .Values.backup.hostPath }}
type: DirectoryOrCreate
{{- if .Values.backup.node }}
nodeSelector:
kubernetes.io/hostname: {{ .Values.backup.node }}
{{- end }}
restartPolicy: OnFailure
{{- end }}
+90
View File
@@ -0,0 +1,90 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "mariadb.fullname" . }}
labels:
{{- include "mariadb.labels" . | nindent 4 }}
annotations:
version-source: dockerhub-tags:library/mariadb
kustomize.toolkit.fluxcd.io/prune: disabled
spec:
replicas: {{ .Values.replicaCount }}
strategy:
type: Recreate
selector:
matchLabels:
{{- include "mariadb.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "mariadb.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: mariadb
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.port }}
env:
- name: MARIADB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.auth.existingSecret }}
key: {{ .Values.auth.rootPasswordKey }}
- name: MARIADB_DATABASE
value: {{ .Values.auth.database | quote }}
{{- if .Values.auth.username }}
- name: MARIADB_USER
value: {{ .Values.auth.username | quote }}
- name: MARIADB_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.auth.existingSecret }}
key: {{ .Values.auth.passwordKey }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: data
mountPath: /var/lib/mysql
readinessProbe:
exec:
command:
- mariadb-admin
- ping
- -h
- localhost
initialDelaySeconds: 15
periodSeconds: 10
livenessProbe:
exec:
command:
- mariadb-admin
- ping
- -h
- localhost
initialDelaySeconds: 30
periodSeconds: 10
volumes:
- name: data
{{- if .Values.persistence.existingClaim }}
persistentVolumeClaim:
claimName: {{ .Values.persistence.existingClaim }}
{{- else if .Values.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ include "mariadb.fullname" . }}-data
{{- else }}
emptyDir: {}
{{- 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 }}
+17
View File
@@ -0,0 +1,17 @@
{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "mariadb.fullname" . }}-data
labels:
{{- include "mariadb.labels" . | nindent 4 }}
annotations:
kustomize.toolkit.fluxcd.io/prune: disabled
spec:
accessModes:
- ReadWriteOnce
storageClassName: {{ .Values.persistence.storageClass }}
resources:
requests:
storage: {{ .Values.persistence.size }}
{{- end }}
+17
View File
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "mariadb.fullname" . }}
labels:
{{- include "mariadb.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
selector:
{{- include "mariadb.selectorLabels" . | nindent 4 }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.port }}
protocol: TCP
{{- if and (eq .Values.service.type "NodePort") .Values.service.nodePort }}
nodePort: {{ .Values.service.nodePort }}
{{- end }}