Error while creating persistanceVolume with mysql on kubernetes Error while creating persistanceVolume with mysql on kubernetes kubernetes kubernetes

Error while creating persistanceVolume with mysql on kubernetes


First of all, using lastest mysql container you are using mysql:8.

--ignore-db-dir flag does not exist in version 8 so you should see in logs this error:

2020-09-21 0 [ERROR] [MY-000068] [Server] unknown option '--ignore-db-dir'.2020-09-21 0 [ERROR] [MY-010119] [Server] Aborting

After removing this flag, mysql stops crashing, but there appears to be other problem.

The hostPath volume does not work as expected. When I runned:

$ kubectl get pvcNAME             STATUS   VOLUME     CAPACITY   ACCESS MODES   STORAGECLASS   AGEmysql-pv-claim   Bound    pvc-xxxx   1Gi        RWO            standard       4m16s

you can see that STORAGECLASS is set to standard, and its causing k8s to provision a pv, instead of using already created one.

# kubectl get pvNAME            CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM                    STORAGECLASS   REASON   AGEpvc-xxxx        1Gi        RWO            Delete           Bound       default/mysql-pv-claim   standard                6m31stask-pv-volume  1Gi        RWO            Retain           Available                                                    6m31s

As you probably see the task-pv-volume status is Available and that means that nothing is using it.

To use it you you need to set storageClassName for Persistent Volume Claim to empty string: "" and maybe add volumeName like following:

apiVersion: v1kind: PersistentVolumeClaimmetadata:  name: mysql-pv-claim  labels:    app: mysql    tier: databasespec:  storageClassName: ""  volumeName: task-pv-volume  accessModes:    - ReadWriteOnce  resources:    requests:      storage: 1Gi

After doing this hostPath volume will work as expected, but there is still a problem with lost+found directory.

My solution would be to create another directory in /mnt/data/ dir e.g. /mnt/data/mysqldata/ and use /mnt/data/mysqldata/ as hostPath in PersistentVolume object.

Other solution would be using older version of mysql that supports --ignore-db-dir flag.