Initializing a MySQL database deployed in an AWS EKS

10/30/2018

I have a pod in my AWS EKS Cluster that runs MySQL:5.7. I have an SQL file that initializes and populates the data for it. in a normal docker-compose, I will use a mount point for it in my docker-compose file:

volumes:
  - ./<path-to-my-config-directory>:/etc/mysql/conf.d
  - ./<path-to-my-persistence-directory>:/var/lib/mysql
  - ./<path-to-my-init.sql>:/docker-entrypoint-initdb.d/init.sql

In EKS, I can create a storage class in which to save MySQL data.

How can I use my init.sql file (about 8GB) to initialize the MySQL pods running in the EKS cluster?

Update: there is another question that explains how to do this if you have a small init file or have access to the Kubernetes host: How to initialize mysql container when created on Kubernetes?

In my case though, I am on AWS EKS and my init file is a few gigabytes, so any help would be greatly appreciated.

-- Reza
amazon-eks
aws-eks
kubernetes
mysql

1 Answer

10/30/2018

It's easy in Kubernetes too. You can do it as follow,

  1. Put your init.sql file into a Kubernetes volume.
  2. Mount this volume into /docker-entrypoint-initdb.d directory of your mysql pod.

Here, is an sample yaml file: mysql-init-demo.yaml

You can also use an init-container to download init.sql file into a Kubernetes volume that is mounted on /docker-entrypoint-initdb.d directory of mysql container.

UPD: As you have specified in update that the solution you have referred won't work for you. I think init-container approach will be best suited for you. Here, is how you can do:

  1. Create a pvc. Let it's name is init-script.
  2. Now, add a init-container to your mysql pod. Mount this init-script pvc at some directory of this init-container. Configure your init-container such that it download your init.sql file on this directory.

  3. Mount the init-script in mysql container at /docker-entrypoint-initdb.d

Let me know if you need any sample with init-container approach.

UPD-2: I have added a sample for init-container approach. You can find it here.

-- Emruz Hossain
Source: StackOverflow