Can't run mysql with an EBS volume in EKS kubernetes

4/9/2020

I am trying to run mysql in EKS (kubernetes v 1.15).

At first I tried to run it using a local volume and it worked well.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/mysql"

When I moved to an EBS volume it ceases to work. I tried using a pvc to the default StorageClass (and to a custom StorageClass I created manually)

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

I tried to attach it to the pod directly using awsBlockStore

volumes:
    - name: mysql-data
      awsElasticBlockStore:
        volumeID: "vol-09df5a8d4c0f2da62"
        fsType: ext4

And nothing seamed to work. the output of kubectl logs mysql-pod is he following:

2020-04-09 11:23:26+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian10 started.
2020-04-09 11:23:26+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-04-09 11:23:26+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian10 started.
2020-04-09 11:23:26+00:00 [Note] [Entrypoint]: Initializing database files
2020-04-09T11:23:26.919072Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-04-09T11:23:26.920523Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2020-04-09T11:23:26.920548Z 0 [ERROR] Aborting
-- M. Iduoad
amazon-eks
aws-eks
eks
kubernetes
mysql

1 Answer

4/9/2020

When running in EKS in order to initiate storage (EBS) you need to use storageClass object.

You can find more information on how to initiate that here

-- Mickey Hovel
Source: StackOverflow