This is to test the use case described here: https://github.com/kubernetes-incubator/external-storage/blob/master/snapshot/doc/volume-snapshotting-proposal.md#alice-wants-to-backup-her-mysql-database-data
The example is copied here:
Example Use Case
Alice wants to backup her MySQL database data
Alice is a DB admin who runs a MySQL database and needs to backup the data on a remote server prior to the database upgrade. She has a short maintenance window dedicated to the operation that allows her to pause the dabase only for a short while. Alice will therefore stop the database, create a snapshot of the data, re-start the database and after that start time-consuming network transfer to the backup server.
The database is running in a pod with the data stored on a persistent volume:
apiVersion: v1
kind: Pod
metadata:
name: mysql
labels:
name: mysql
spec:
containers:
- resources:
limits :
cpu: 0.5
image: openshift/mysql-55-centos7
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: rootpassword
- name: MYSQL_USER
value: wp_user
- name: MYSQL_PASSWORD
value: wp_pass
- name: MYSQL_DATABASE
value: wp_db
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql/data
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: claim-mysql
The persistent volume is bound to the claim-mysql
PVC which needs to be snapshotted. Since Alice has some downtime allowed she may lock the database tables for a moment to ensure the backup would be consistent:
mysql> FLUSH TABLES WITH READ LOCK;
Now she is ready to create a snapshot of the claim-mysql
PVC. She creates a vs.yaml:
apiVersion: v1
kind: VolumeSnapshot
metadata:
name: mysql-snapshot
namespace: default
spec:
persistentVolumeClaim: claim-mysql
$ kubectl create -f vs.yaml
This will result in a new snapshot being created by the controller. Alice would wait until the snapshot is complete:
$ kubectl get volumesnapshots
NAME STATUS
mysql-snapshot ready
Now it's OK to unlock the database tables and the database may return to normal operation:
Alice can now get to the snapshotted data and start syncing them to the remote server. First she needs to promote the snapshot to a PV by creating a new PVC. To use the external provisioner a new storage class must be created:
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: snapshot-promoter
provisioner: volumesnapshot.external-storage.k8s.io/snapshot-promoter
Now Alice can create the PVC referencing the snapshot in the annotations.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: snapshot-data-claim
annotations:
snapshot.alpha.kubernetes.io/snapshot: mysql-snapshot
spec:
accessModes:
- ReadWriteOnce
storageClassName: snapshot-promoter
Once the claim is bound to a persistent volume Alice creates a job to sync the data with a remote backup server:
apiVersion: batch/v1
kind: Job
metadata:
name: mysql-sync
spec:
template:
metadata:
name: mysql-sync
spec:
containers:
- name: mysql-sync
image: rsync
command: "rsync -av /mnt/data [email protected]:mysql_backups"
restartPolicy: Never
volumeMounts:
- name: snapshot-data
mountPath: /mnt/data
volumes:
- name: snapshot-data
persistentVolumeClaim:
claimName: snapshot-data-claim
Alice will wait for the job to finish and then may delete both the snapshot-data-claim
PVC as well as mysql-snapshot
request (which will delete also the snapshot object):
$ kubectl delete pvc snapshot-data-claim
$ kubectl delete volumesnapshot mysql-snapshot