mirror of
https://github.com/helm/charts.git
synced 2026-08-23 22:37:45 +00:00
mysqldump: Add support for existing secret for mysql password (#15480)
Signed-off-by: Marcus Sonestedt <marcus.s.lindblom@gmail.com> Signed-off-by: Marcus Sonestedt <marcus.sonestedt@barium.se>
This commit is contained in:
committed by
Kubernetes Prow Robot
parent
4d1ca2afa6
commit
6dd91c92bc
@@ -2,7 +2,7 @@ apiVersion: v1
|
||||
appVersion: 2.4.1
|
||||
description: A Helm chart to help backup MySQL databases using mysqldump
|
||||
name: mysqldump
|
||||
version: 2.4.2
|
||||
version: 2.5.0
|
||||
keywords:
|
||||
- mysql
|
||||
- mysqldump
|
||||
|
||||
+13
-10
@@ -2,10 +2,10 @@
|
||||
|
||||
mysqldump is a tool for creating backups of MySQL databases in the form of a .sql file.
|
||||
|
||||
## TL;DR;
|
||||
## TLDR
|
||||
|
||||
```console
|
||||
$ helm install stable/mysqldump \
|
||||
helm install stable/mysqldump \
|
||||
--set mysql.host=mysql;mysql.username=root,mysql.password=password,persistence.enabled=true
|
||||
```
|
||||
|
||||
@@ -15,14 +15,14 @@ This chart helps set up a cronjob or one time job to backup a MySQL database wit
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Kubernetes 1.8
|
||||
- Kubernetes 1.8
|
||||
|
||||
## Installing the Chart
|
||||
|
||||
To install the chart with the release name `my-release`:
|
||||
|
||||
```console
|
||||
$ helm install stable/mysqldump \
|
||||
helm install stable/mysqldump \
|
||||
--set mysql.host=mysql,mysql.username=root,mysql.password=password,persistence.enabled=true
|
||||
```
|
||||
|
||||
@@ -35,7 +35,7 @@ This command will create a cronjob to run a job once a day to backup the databas
|
||||
To uninstall/delete the `my-release` deployment:
|
||||
|
||||
```console
|
||||
$ helm delete my-release
|
||||
helm delete my-release
|
||||
```
|
||||
|
||||
The command removes all the Kubernetes components associated with the chart and deletes the release.
|
||||
@@ -47,16 +47,19 @@ The following tables lists the configurable parameters of the mysqldump chart an
|
||||
| Parameter | Description | Default |
|
||||
| --------------------------------------------- | ------------------------------------------------------------------------------ | ---------------------------- |
|
||||
| image.repository | Name of image to use | monotek/gcloud-mysql |
|
||||
| image.tag | Version of image to use | "6" |
|
||||
| image.tag | Version of image to use | "8" |
|
||||
| image.pullPolicy | Pull Policy to use for image | IfNotPresent |
|
||||
| mysql.db | single mysql db to backup (optional) | mysql |
|
||||
| mysql.host | mysql host to backup | mysql |
|
||||
| mysql.username | mysql username | root |
|
||||
| mysql.password | mysql password | "" |
|
||||
| mysql.existingSecret | existing secret name, used to get mysql password (if set) | |
|
||||
| mysql.existingSecretKey | existing secret key | mysql-root-password |
|
||||
| mysql.port | mysql port | 3306 |
|
||||
| schedule | crontab schedule to run on. set as `now` to run as a one time job | "0/5 \* \* \* \*" |
|
||||
| schedule | crontab schedule to run on. set as `now` to run as a one time job | "0 3 \* \* \*" |
|
||||
| options | options to pass onto MySQL | "--opt --single-transaction" |
|
||||
| debug | print some extra debug logs during backup | false |
|
||||
| dumpAllToStdout | dump all database contents to stdout when not uploading | false |
|
||||
| additionalSteps | run these extra shell steps after all backup jobs completed | [] |
|
||||
| successfulJobsHistoryLimit | number of successful jobs to remember | 5 |
|
||||
| failedJobsHistoryLimit | number of failed jobs to remember | 5 |
|
||||
@@ -67,7 +70,7 @@ The following tables lists the configurable parameters of the mysqldump chart an
|
||||
| persistence.storageClass | storage class to use for PVC | |
|
||||
| persistence.subPath | subPath for PVC | |
|
||||
| allDatabases.enabled | backup all databases | true |
|
||||
| allDatabases.SingleSqlFile | backup all databases to singel file | false |
|
||||
| allDatabases.SingleSqlFile | backup all databases to single file | false |
|
||||
| housekeeping.enabled | delete olf backups in pvc | true |
|
||||
| housekeeping.keepDays | keep last x days of backups in PVC | 10 |
|
||||
| saveToDirectory | saves the sql backup to a directory named like the database or alldatabases | false |
|
||||
@@ -92,12 +95,12 @@ The following tables lists the configurable parameters of the mysqldump chart an
|
||||
By enabling the flag `upload.googlestoragebucket.usingGCPController` and having a GCP Service Account Controller deployed in your cluster, it is possible to autogenerate and inject the service account used for the storage bucket access. For more information see <https://github.com/kiwigrid/helm-charts/tree/master/charts/gcp-serviceaccount-controller>
|
||||
|
||||
```console
|
||||
$ helm install stable/mysqldump --name my-release \
|
||||
helm install stable/mysqldump --name my-release \
|
||||
--set persistentVolumeClaim=name-of-existing-pvc
|
||||
```
|
||||
|
||||
Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example,
|
||||
|
||||
```console
|
||||
$ helm install stable/mysqldump --name my-release -f values.yaml
|
||||
helm install stable/mysqldump --name my-release -f values.yaml
|
||||
```
|
||||
|
||||
Regular → Executable
+14
@@ -4,11 +4,25 @@ spec:
|
||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
|
||||
command: ["/bin/bash", "/scripts/backup.sh"]
|
||||
{{- if .Values.mysql.existingSecret }}
|
||||
env:
|
||||
- name: MYSQL_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ .Values.mysql.existingSecret | quote }}
|
||||
{{- if .Values.mysql.existingSecretKey }}
|
||||
key: {{ .Values.mysql.existingSecretKey | quote }}
|
||||
{{- else }}
|
||||
key: "mysql-root-password"
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: "{{ template "mysqldump.fullname" . }}"
|
||||
{{- if not .Values.mysql.existingSecret }}
|
||||
- secretRef:
|
||||
name: "{{ template "mysqldump.fullname" . }}"
|
||||
{{- end }}
|
||||
volumeMounts:
|
||||
- name: backups
|
||||
mountPath: /backup
|
||||
|
||||
Regular → Executable
+22
-15
@@ -36,7 +36,7 @@ data:
|
||||
TIMESTAMP="$(date +%Y%m%d%H%M%S)"
|
||||
|
||||
echo "test mysql connection"
|
||||
if [ -z "$(mysql -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if .Values.mysql.password }} -p${MYSQL_PASSWORD}{{ end }} -B -N -e 'SHOW DATABASES;')" ]; then
|
||||
if [ -z "$(mysql -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if or .Values.mysql.password .Values.mysql.existingSecret }} -p${MYSQL_PASSWORD}{{ end }} -B -N -e 'SHOW DATABASES;')" ]; then
|
||||
echo "mysql connection failed! exiting..."
|
||||
exit 1
|
||||
fi
|
||||
@@ -54,13 +54,13 @@ data:
|
||||
MYSQL_DB="{{ .Values.mysql.db }}"
|
||||
echo "Backing up single db ${MYSQL_DB}"
|
||||
{{ if .Values.saveToDirectory }}mkdir -p "${BACKUP_DIR}"/"${MYSQL_DB}"{{ end }}
|
||||
mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if .Values.mysql.password }} -p${MYSQL_PASSWORD}{{ end }} --databases ${MYSQL_DB} | gzip > ${BACKUP_DIR}/{{ if .Values.saveToDirectory }}${MYSQL_DB}/{{ end }}${TIMESTAMP}_${MYSQL_DB}.sql.gz
|
||||
mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if or .Values.mysql.password .Values.mysql.existingSecret }} -p${MYSQL_PASSWORD}{{ end }} --databases ${MYSQL_DB} | gzip > ${BACKUP_DIR}/{{ if .Values.saveToDirectory }}${MYSQL_DB}/{{ end }}${TIMESTAMP}_${MYSQL_DB}.sql.gz
|
||||
rc=$?
|
||||
{{ else if and (.Values.allDatabases.enabled) (eq .Values.allDatabases.singleBackupFile false)}}
|
||||
for MYSQL_DB in $(mysql -h "${MYSQL_HOST}" -u ${MYSQL_USERNAME}{{ if .Values.mysql.password }} -p${MYSQL_PASSWORD}{{ end }} -B -N -e "SHOW DATABASES;"|egrep -v '^(information|performance)_schema$'); do
|
||||
for MYSQL_DB in $(mysql -h "${MYSQL_HOST}" -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if or .Values.mysql.password .Values.mysql.existingSecret }} -p${MYSQL_PASSWORD}{{ end }} -B -N -e "SHOW DATABASES;"|egrep -v '^(information|performance)_schema$'); do
|
||||
echo "Backing up db ${MYSQL_DB}"
|
||||
{{ if .Values.saveToDirectory }}mkdir -p "${BACKUP_DIR}"/"${MYSQL_DB}"{{ end }}
|
||||
mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -u ${MYSQL_USERNAME}{{ if .Values.mysql.password }} -p${MYSQL_PASSWORD}{{ end }} --databases ${MYSQL_DB} | gzip > ${BACKUP_DIR}/{{ if .Values.saveToDirectory }}${MYSQL_DB}/{{ end }}${TIMESTAMP}_${MYSQL_DB}.sql.gz
|
||||
mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if or .Values.mysql.password .Values.mysql.existingSecret }} -p${MYSQL_PASSWORD}{{ end }} --databases ${MYSQL_DB} | gzip > ${BACKUP_DIR}/{{ if .Values.saveToDirectory }}${MYSQL_DB}/{{ end }}${TIMESTAMP}_${MYSQL_DB}.sql.gz
|
||||
rc=$?
|
||||
done
|
||||
|
||||
@@ -68,7 +68,7 @@ data:
|
||||
echo "Backing up all databases"
|
||||
MYSQL_DB="alldatabases"
|
||||
{{ if .Values.saveToDirectory }}mkdir -p "${BACKUP_DIR}"/"${MYSQL_DB}"{{ end }}
|
||||
mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if .Values.mysql.password }} -p${MYSQL_PASSWORD}{{ end }} --all-databases | gzip > ${BACKUP_DIR}/{{ if .Values.saveToDirectory }}${MYSQL_DB}/{{ end }}${TIMESTAMP}_${MYSQL_DB}.sql.gz
|
||||
mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if or .Values.mysql.password .Values.mysql.existingSecret }} -p${MYSQL_PASSWORD}{{ end }} --all-databases | gzip > ${BACKUP_DIR}/{{ if .Values.saveToDirectory }}${MYSQL_DB}/{{ end }}${TIMESTAMP}_${MYSQL_DB}.sql.gz
|
||||
rc=$?
|
||||
{{- end -}}
|
||||
|
||||
@@ -91,12 +91,18 @@ data:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
{{- else }}
|
||||
mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if .Values.mysql.password }} -p${MYSQL_PASSWORD}{{ end }} --all-databases
|
||||
{{- else }}
|
||||
{{ if .Values.dumpAllToStdout }}
|
||||
mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if or .Values.mysql.password .Values.mysql.existingSecret }} -p${MYSQL_PASSWORD}{{ end }} --all-databases
|
||||
rc=$?
|
||||
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if .Values.debug }}
|
||||
echo Contents of ${BACKUP_DIR}
|
||||
ls -lahR ${BACKUP_DIR}
|
||||
{{ end }}
|
||||
|
||||
if [ "$rc" != "0" ]; then
|
||||
echo "backup failed"
|
||||
@@ -104,13 +110,14 @@ data:
|
||||
fi
|
||||
|
||||
{{ if .Values.additionalSteps }}
|
||||
{{- range .Values.additionalSteps }}
|
||||
{{ . }}
|
||||
{{- end }}
|
||||
{{- range .Values.additionalSteps }}
|
||||
{{ . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{ if .Values.debug }}
|
||||
ls -alh ${BACKUP_DIR}
|
||||
{{ end }}
|
||||
echo "complete" > ${BACKUP_DIR}/${TIMESTAMP}.state
|
||||
echo "Backup successful! :-)"
|
||||
|
||||
echo "Disk usage in ${BACKUP_DIR}"
|
||||
du -h -d 2 ${BACKUP_DIR}
|
||||
|
||||
echo "Backup successful! :-)"
|
||||
@@ -3,8 +3,12 @@
|
||||
# Declare variables to be passed into your templates.
|
||||
|
||||
image:
|
||||
registry: docker.io
|
||||
repository: monotek/gcloud-mysql
|
||||
tag: "8"
|
||||
## Specify a imagePullPolicy
|
||||
## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
|
||||
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images#
|
||||
pullPolicy: IfNotPresent
|
||||
|
||||
mysql:
|
||||
@@ -12,12 +16,16 @@ mysql:
|
||||
## to be used only when there's an existing database to backup.
|
||||
host: ""
|
||||
username: root
|
||||
# overriden by existingDbSecret / existingDbSecretKey if set
|
||||
password:
|
||||
port: 3306
|
||||
# db for single db backup
|
||||
db: dbname
|
||||
# Get password from existing secret
|
||||
# existingSecret:
|
||||
# existingSecretKey:
|
||||
|
||||
# use --all-databases
|
||||
# use --all-databases if enabled
|
||||
allDatabases:
|
||||
enabled: true
|
||||
# creates single backup file with all databases
|
||||
@@ -29,6 +37,9 @@ options: "--opt --single-transaction"
|
||||
# save sql backup to a directory named like the database or "alldatabases"
|
||||
saveToDirectory: false
|
||||
|
||||
# if to dump all databases to stdout when not uploading
|
||||
dumpAllToStdout: false
|
||||
|
||||
## set to `now` to get a one time job, or a cronjob schedule like `0 0 * * *`
|
||||
## to get a cronjob.
|
||||
schedule: "0 3 * * *"
|
||||
@@ -66,7 +77,7 @@ persistence:
|
||||
##
|
||||
# storageClass: "-"
|
||||
|
||||
# delete backups older than 10 days
|
||||
# delete old backups
|
||||
housekeeping:
|
||||
enabled: true
|
||||
keepDays: 10
|
||||
@@ -87,6 +98,7 @@ upload:
|
||||
# serviceAccountName
|
||||
# usingGCPController to enable autogeneration and injection of the service account
|
||||
usingGCPController: false
|
||||
|
||||
ssh:
|
||||
enabled: false
|
||||
user: backup
|
||||
|
||||
Reference in New Issue
Block a user