问题
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,
- Put your
init.sql
file into a Kubernetes volume. - 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:
- Create a pvc. Let it's name is
init-script
. Now, add a
init-container
to your mysql pod. Mount thisinit-script
pvc at some directory of thisinit-container
. Configure yourinit-container
such that it download yourinit.sql
file on this directory.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