Initializing a MySQL database deployed in an AWS EKS

吃可爱长大的小学妹 提交于 2019-12-20 07:36:53

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/53065935/initializing-a-mysql-database-deployed-in-an-aws-eks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!