forked from helm/charts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new chart stable/mysqldump (helm#4069)
* new chart stable/mysqldump Helps the user backup mysql databases to a persistent volume * use chart.name from tpl, add app label * add app/chart fixes to mysqldump-cron.yaml * fix backoffLimit in wrong place. * exit gracefully if db host not specified Signed-off-by: aba182 <ajwilhel@gmail.com>
- Loading branch information
Showing
14 changed files
with
424 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# 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 | ||
*~ | ||
# Various IDEs | ||
.project | ||
.idea/ | ||
*.tmproj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: v1 | ||
appVersion: 5.7.21 | ||
description: A Helm chart to help backup MySQL databases using mysqldump | ||
name: mysqldump | ||
version: 0.1.0 | ||
keywords: | ||
- mysql | ||
- mysqldump | ||
- backup | ||
home: https://www.mysql.com/ | ||
icon: https://www.mysql.com/common/logos/logo-mysql-170x115.png | ||
sources: | ||
- https://github.com/kubernetes/charts | ||
- https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html | ||
maintainers: | ||
- name: paulczar | ||
email: username.taken@gmail.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
approvers: | ||
- paulczar | ||
reviewers: | ||
- paulczar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# mysqldump | ||
|
||
mysqldump is a tool for creating backups of MySQL databases in the form of a .sql file. | ||
|
||
## TL;DR; | ||
|
||
```console | ||
$ helm install stable/mysqldump \ | ||
--set mysql.host=mysql;mysql.username=root,mysql.password=password,persistence.enabled=true | ||
``` | ||
|
||
## Introduction | ||
|
||
This chart helps set up a cronjob or one time job to backup a MySQL database with mysqldump into a Persistent Volume. You can specify an existing PVC, or helm will create one for you. | ||
|
||
|
||
## Prerequisites | ||
- Kubernetes 1.8 | ||
|
||
## Installing the Chart | ||
|
||
To install the chart with the release name `my-release`: | ||
|
||
```console | ||
$ helm install stable/mysqldump \ | ||
--set mysql.host=mysql,mysql.username=root,mysql.password=password,persistence.enabled=true | ||
``` | ||
|
||
This command will create a cronjob to run a job once a day to backup the databases found on the host `mysql` | ||
|
||
> **Tip**: List all releases using `helm list` | ||
## Uninstalling the Chart | ||
|
||
To uninstall/delete the `my-release` deployment: | ||
|
||
```console | ||
$ helm delete my-release | ||
``` | ||
|
||
The command removes all the Kubernetes components associated with the chart and deletes the release. | ||
|
||
## Configuration | ||
|
||
The following tables lists the configurable parameters of the mysqldump chart and their default values. | ||
|
||
Parameter | Description | Default | ||
--- | --- | --- | ||
image.repository | Name of MySQL image to use | mysql | ||
image.tag | Version of MySQL image to use | "5" | ||
image.pullPolicy | Pull Policy to use for image | IfNotPresent | ||
mysql.host | mysql host to backup | mysql | ||
mysql.username | mysql username | root | ||
mysql.password | mysql password | "" | ||
mysql.port | mysql port | 3306 | ||
schedule | crontab schedule to run on. set as `now` to run as a one time job | "0/5 * * * *" | ||
options | options to pass onto MySQL | "--opt --skip-lock-tables --skip-add-locks --all-databases" | ||
debug | print some extra debug logs during backup | false | ||
successfulJobsHistoryLimit | number of successful jobs to remember | 5 | ||
failedJobsHistoryLimit | number of failed jobs to remember | 5 | ||
persistentVolumeClaim | existing Persistent Volume Claim to backup to, leave blank to create a new one | | ||
persistence.enabled | create new PVC (unless `persistentVolumeClaim` is set) | true | ||
persistence.size | size of PVC to create | 8Gi | ||
persistence.accessMode | accessMode to use for PVC | ReadWriteOnce | ||
persistence.storageClass | storage class to use for PVC | | ||
|
||
```console | ||
$ helm install stable/nginx-ingress --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/nginx-ingress --name my-release -f values.yaml | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
spec: | ||
containers: | ||
- name: xtrabackup | ||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" | ||
imagePullPolicy: {{ .Values.image.pullPolicy | quote }} | ||
command: ["/bin/bash", "/scripts/backup.sh"] | ||
envFrom: | ||
- configMapRef: | ||
name: "{{ template "mysqldump.fullname" . }}" | ||
- secretRef: | ||
name: "{{ template "mysqldump.fullname" . }}" | ||
volumeMounts: | ||
- name: backups | ||
mountPath: /backup | ||
- name: xtrabackup-script | ||
mountPath: /scripts | ||
restartPolicy: Never | ||
volumes: | ||
- name: backups | ||
{{- if .Values.persistentVolumeClaim }} | ||
persistentVolumeClaim: | ||
claimName: {{ .Values.persistentVolumeClaim }} | ||
{{- else -}} | ||
{{- if .Values.persistence.enabled }} | ||
persistentVolumeClaim: | ||
claimName: {{ template "mysqldump.fullname" . }} | ||
{{- else }} | ||
emptyDir: {} | ||
{{- end }} | ||
{{- end }} | ||
- name: xtrabackup-script | ||
configMap: | ||
name: {{ template "mysqldump.fullname" . }}-script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{{- if eq .Values.schedule "now" }} | ||
|
||
Running mysqldump now. | ||
|
||
For job status run: | ||
|
||
$ kubectl get job {{ template "mysqldump.fullname" . }} -o wide | ||
|
||
$ kubectl get pods --selector=job-name={{ template "mysqldump.fullname" . }} --show-all -o wide | ||
|
||
To see the logs from the backup job run: | ||
|
||
$ kubectl logs `kc get pods --selector=job-name=test-mysqldump --output=jsonpath={.items..metadata.name}` | ||
|
||
mysqldump contents can be found in: | ||
{{- if .Values.persistentVolumeClaim }} | ||
$ kubectl get persistentvolumeclaim {{ .Values.persistentVolumeClaim }} | ||
{{- else -}} | ||
{{- if .Values.persistence.enabled }} | ||
$ kubectl get persistentvolumeclaim {{ template "mysqldump.fullname" . }} | ||
{{- else }} | ||
$ kubectl logs `kc get pods --selector=job-name=test-mysqldump --output=jsonpath={.items..metadata.name}` | ||
{{- end -}} | ||
{{- end }} | ||
|
||
{{- else }} | ||
|
||
Running mysqldump on crontab schedule "{{ .Values.schedule }}" | ||
|
||
For cronjob status run: | ||
|
||
$ kubectl get cronjob {{ template "mysqldump.fullname" . }} -o wide | ||
|
||
$ kubectl get jobs --selector=cronjob-name={{ template "mysqldump.fullname" . }} | ||
|
||
To see the logs from the most recent backup job run: | ||
|
||
$ kubectl logs $(kc get pods --selector \ | ||
job-name=$(kc get jobs --selector=cronjob-name={{ template "mysqldump.fullname" . }} \ | ||
--output=jsonpath='{.items[-1:].metadata.name}') \ | ||
--output=jsonpath={.items..metadata.name}) | ||
|
||
mysqldump contents can be found in: | ||
{{- if .Values.persistentVolumeClaim }} | ||
$ kubectl get persistentvolumeclaim {{ .Values.persistentVolumeClaim }} | ||
{{- else -}} | ||
{{- if .Values.persistence.enabled }} | ||
$ kubectl get persistentvolumeclaim {{ template "mysqldump.fullname" . }} | ||
{{- else }} | ||
$ kubectl logs `kc get pods --selector=job-name=test-mysqldump --output=jsonpath={.items..metadata.name}` | ||
{{- end -}} | ||
{{- end }} | ||
|
||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{{/* vim: set filetype=mustache: */}} | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "mysqldump.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 "mysqldump.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 "mysqldump.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ template "mysqldump.fullname" . }} | ||
labels: | ||
app: {{ template "mysqldump.name" . }} | ||
chart: {{ template "mysqldump.chart" . }} | ||
release: "{{ .Release.Name }}" | ||
heritage: "{{ .Release.Service }}" | ||
data: | ||
MYSQL_HOST: {{ .Values.mysql.host | quote }} | ||
MYSQL_USERNAME: {{ .Values.mysql.username | quote }} | ||
MYSQL_PORT: {{ .Values.mysql.port | quote }} | ||
MYSQL_OPTS: {{ .Values.options | quote }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{{- if ne .Values.schedule "now" -}} | ||
apiVersion: batch/v1beta1 | ||
kind: CronJob | ||
metadata: | ||
name: {{ template "mysqldump.fullname" . }} | ||
labels: | ||
app: {{ template "mysqldump.name" . }} | ||
chart: {{ template "mysqldump.chart" . }} | ||
release: "{{ .Release.Name }}" | ||
heritage: "{{ .Release.Service }}" | ||
spec: | ||
schedule: "{{ .Values.schedule }}" | ||
successfulJobsHistoryLimit: {{ .Values.successfulJobsHistoryLimit }} | ||
failedJobsHistoryLimit: {{ .Values.failedJobsHistoryLimit }} | ||
concurrencyPolicy: Forbid | ||
jobTemplate: | ||
metadata: | ||
labels: | ||
app: {{ template "mysqldump.name" . }} | ||
chart: {{ template "mysqldump.chart" . }} | ||
cronjob-name: {{ template "mysqldump.fullname" . }} | ||
release: "{{ .Release.Name }}" | ||
heritage: "{{ .Release.Service }}" | ||
spec: | ||
backoffLimit: 1 | ||
template: | ||
{{- $file := .Files.Get "files/job.tpl" }} | ||
{{ tpl $file . | indent 8 }} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{{- if eq .Values.schedule "now" -}} | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: {{ template "mysqldump.fullname" . }} | ||
labels: | ||
app: {{ template "mysqldump.name" . }} | ||
chart: {{ template "mysqldump.chart" . }} | ||
release: "{{ .Release.Name }}" | ||
heritage: "{{ .Release.Service }}" | ||
spec: | ||
backoffLimit: 1 | ||
template: | ||
{{ $file := .Files.Get "files/job.tpl" }} | ||
{{ tpl $file . | indent 4 }} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{{- if .Values.persistence.enabled }} | ||
{{- if not .Values.persistentVolumeClaim }} | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: {{ template "mysqldump.fullname" . }} | ||
labels: | ||
app: {{ template "mysqldump.name" . }} | ||
chart: {{ template "mysqldump.chart" . }} | ||
release: "{{ .Release.Name }}" | ||
heritage: "{{ .Release.Service }}" | ||
spec: | ||
accessModes: [{{ .Values.persistence.accessMode | quote }}] | ||
{{- if .Values.persistence.storageClass }} | ||
{{- if (eq "-" .Values.persistence.storageClass) }} | ||
storageClassName: "" | ||
{{- else }} | ||
storageClassName: "{{ .Values.persistence.storageClass }}" | ||
{{- end }} | ||
{{- end }} | ||
resources: | ||
requests: | ||
storage: {{ .Values.persistence.size }} | ||
{{- end -}} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ template "mysqldump.fullname" . }}-script | ||
labels: | ||
app: {{ template "mysqldump.name" . }} | ||
chart: {{ template "mysqldump.chart" . }} | ||
release: "{{ .Release.Name }}" | ||
heritage: "{{ .Release.Service }}" | ||
data: | ||
backup.sh: |- | ||
{{- if .Values.debug }} | ||
set -x | ||
{{- end }} | ||
if [[ -z ${MYSQL_HOST} ]]; then | ||
echo "no MySQL host specified. Nothing to do here." | ||
exit 0 | ||
fi | ||
echo "Backing up database" | ||
DATE=$(date +%Y%m%d%H%M%S) | ||
echo "started" > /backup/${DATE}.state | ||
[[ -n ${MYSQL_USERNAME} ]] && USER="--user=${MYSQL_USERNAME}" | ||
[[ -n ${MYSQL_PASSWORD} ]] && PASS="--password=${MYSQL_PASSWORD}" | ||
[[ -n ${MYSQL_HOST} ]] && HOST="--host=${MYSQL_HOST}" | ||
[[ -n ${MYSQL_PORT} ]] && PORT="--port=${MYSQL_PORT}" | ||
CREDS="${USER} ${PASS} ${HOST} ${PORT}" | ||
{{- if (.Values.persistence.enabled) or (.Values.persistentVolumeClaim) }} | ||
mysqldump ${CREDS} ${MYSQL_OPTS} > /backup/${DATE}.sql | ||
{{- else }} | ||
mysqldump ${CREDS} ${MYSQL_OPTS} | ||
{{- end }} | ||
rc=$? | ||
if [[ $rc != 0 ]]; then | ||
echo "backup failed" | ||
exit 1 | ||
fi | ||
echo "complete" > /backup/${DATE}.state | ||
echo "backup complete - /backup/${DATE}.sql" | ||
{{- if .Values.debug }} | ||
ls -alh /backup | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: "{{ template "mysqldump.fullname" . }}" | ||
labels: | ||
app: {{ template "mysqldump.name" . }} | ||
chart: {{ template "mysqldump.chart" . }} | ||
release: "{{ .Release.Name }}" | ||
heritage: "{{ .Release.Service }}" | ||
type: Opaque | ||
data: | ||
{{- if .Values.mysql.password }} | ||
MYSQL_PASSWORD: {{ .Values.mysql.password | b64enc | quote }} | ||
{{- end -}} |
Oops, something went wrong.