初始化部署在AWS EKS中的MySQL数据库 [英] Initializing a MySQL database deployed in an AWS EKS

查看:302
本文介绍了初始化部署在AWS EKS中的MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的AWS EKS集群中有一个运行MySQL:5.7的Pod.我有一个SQL文件,该文件初始化并填充它的数据.在普通的docker-compose中,我将在docker-compose文件中为其使用挂载点:

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

在EKS中,我可以创建一个存储类来保存MySQL数据.

如何使用init.sql文件(约8GB)初始化EKS集群中运行的MySQL Pod?

更新:如果您的初始化文件很小或可以访问Kubernetes主机,还有一个问题可以说明如何执行此操作:解决方案

在Kubernetes中也很容易.您可以按照以下步骤进行操作,

  1. 将您的init.sql文件放入 Kubernetes卷.
  2. 将该卷安装到mysql pod的/docker-entrypoint-initdb.d目录中.

这是一个示例yaml文件: mysql-init-demo.yaml

您还可以使用init-containerinit.sql文件下载到安装在mysql容器/docker-entrypoint-initdb.d目录中的Kubernetes卷中.

UPD::正如您在更新中指定的那样,您引用的解决方案将对您不起作用.我认为init-container方法将最适合您.这是您的操作方式:

  1. 创建一个pvc.命名为init-script.
  2. 现在,将init-container添加到您的mysql pod中.将此init-script pvc安装在此init-container的某个目录中.配置您的init-container,使其将您的init.sql文件下载到此目录中.

  3. /docker-entrypoint-initdb.d

  4. 的mysql容器中安装init-script

让我知道您是否需要使用init-container方法进行采样.

UPD-2::我为init-container方法添加了一个示例.您可以在此处找到它.

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.

解决方案

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.

这篇关于初始化部署在AWS EKS中的MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆