From 83ba9575f9ae4faba38b57c6d9f6d0889259cd55 Mon Sep 17 00:00:00 2001 From: Anthony Yeh Date: Wed, 18 Jan 2017 14:25:06 -0800 Subject: [PATCH] Use subPath to keep data dir out of volume root. The data dir should not be at the root of the volume, because many volume types create files or directories there automatically. The database initialization script requires the data dir to be empty, and we shouldn't try to guess which files may exist. In particular, by retaining lost+found, it also becomes possible to recover files that end up there. --- docs/tutorials/stateful-application/mysql-statefulset.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/tutorials/stateful-application/mysql-statefulset.yaml b/docs/tutorials/stateful-application/mysql-statefulset.yaml index 106f77cd99..d8ee2d9ac9 100644 --- a/docs/tutorials/stateful-application/mysql-statefulset.yaml +++ b/docs/tutorials/stateful-application/mysql-statefulset.yaml @@ -16,8 +16,6 @@ spec: "image": "mysql:5.7", "command": ["bash", "-c", " set -ex\n - # mysqld --initialize expects an empty data dir.\n - rm -rf /mnt/data/lost+found\n # Generate mysql server-id from pod ordinal index.\n [[ `hostname` =~ -([0-9]+)$ ]] || exit 1\n ordinal=${BASH_REMATCH[1]}\n @@ -32,7 +30,6 @@ spec: fi\n "], "volumeMounts": [ - {"name": "data", "mountPath": "/mnt/data"}, {"name": "conf", "mountPath": "/mnt/conf.d"}, {"name": "config-map", "mountPath": "/mnt/config-map"} ] @@ -54,7 +51,7 @@ spec: xtrabackup --prepare --target-dir=/var/lib/mysql\n "], "volumeMounts": [ - {"name": "data", "mountPath": "/var/lib/mysql"}, + {"name": "data", "mountPath": "/var/lib/mysql", "subPath": "mysql"}, {"name": "conf", "mountPath": "/etc/mysql/conf.d"} ] } @@ -72,6 +69,7 @@ spec: volumeMounts: - name: data mountPath: /var/lib/mysql + subPath: mysql - name: conf mountPath: /etc/mysql/conf.d resources: @@ -140,6 +138,7 @@ spec: volumeMounts: - name: data mountPath: /var/lib/mysql + subPath: mysql - name: conf mountPath: /etc/mysql/conf.d resources: