Mysql k8s Pod with mount volume on AWS failing

4/16/2018

I tried mysql with mount-volume to obtain persistence across /var/lib/mysql

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
 ---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: mysql
spec:
 selector:
   matchLabels:
     app: mysql
 strategy:
   type: Recreate
 template:
   metadata:
     labels:
       app: mysql
   spec:
    containers:
    - image: mysql:5.6
      name: mysql
      env:
      - name: MYSQL_ROOT_PASSWORD
        value: password
      ports:
      - containerPort: 3306
        name: mysql
      volumeMounts:
      - name: mysql-persistent-storage
        mountPath: /var/lib/mysql
     volumes:
     - name: mysql-persistent-storage
       persistentVolumeClaim:
         claimName: mysql-pv-claim

kubelogs as below

sh-3.2# kubectl logs acds-catchup-db-6f7d4b6c5b-2jwds  
Initializing database
2018-04-16T09:23:18.020740Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-04-16T09:23:18.022014Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2018-04-16T09:23:18.022037Z 0 [ERROR] Aborting

On investigating, I found a directory with name Lost+Found creating in MountVolume.

Can any help me on this issue

-- Ravichandra
amazon-web-services
kubernetes
mysql

1 Answer

4/16/2018

That directory is always present in the root path of the volume, so you cannot just remove it.

You have 2 options how to fix it:

  1. Add --ignore-db-dir=lost+found option to the MySQL configuration. I think that is the better way.
  2. Set the database directory to the path inside the volume, not to the root path of the volume. You can specify the database directory by --datadir= option.

Here is the example of args settings:

spec:
  containers:
  - name: mysql
    image: mysql:5.6
    args: ["--ignore-db-dir=lost+found"]
-- Anton Kostenko
Source: StackOverflow