简体   繁体   English

在 kubernetes 初始化容器中运行 mysql

[英]running mysql in a kubernetes init container

I am running mysql as an init container for a kubernetes deployment.我正在运行 mysql 作为 kubernetes 部署的初始化容器。

For various reasons i need to spin up mysql in a init container/restore a mysql dump -> save it to a pvc and then the main pod will be a mysql pod with the data attached.由于各种原因,我需要在初始化容器中启动 mysql/恢复 mysql 转储 -> 将其保存到 pvc,然后主 pod 将是一个 mysql 附加数据

This is because i need to take a snapshot of the disk and im going to have CI watch for the pod to be "ready/running" before i take the snapshot.这是因为我需要拍摄磁盘快照,并且在拍摄快照之前,我将让 CI 监视 pod 是否“准备好/运行”。

So i cant just dump the dump.sql in docker-entrypoint-initdb.d and be done with it.所以我不能只在 docker-entrypoint-initdb.d 中转储 dump.sql 并完成它。

This is because the volumesnapshot kubernetes resources would be taken before the data is restored/ready.这是因为volumesnapshot kubernetes 资源将在数据恢复/准备好之前被占用。 Hence why i need the data to be prepared in an init container.因此,为什么我需要在初始化容器中准备数据。

The problem i am having is an init container needs a command which overwrites the entrypoint.sh (which actually starts mysql ect)我遇到的问题是初始化容器需要一个覆盖 entrypoint.sh 的命令(实际上启动 mysql 等)

So far i have this bash script which is run on the container startup.到目前为止,我有这个在容器启动时运行的 bash 脚本。

./entrypoint.sh --ignore-db-dir=lost+found 
echo "done" (this is just purely for testing purposes to see if it ever gets processed and it doesnt)
mysql -u root -ppassword < /data/backups/backup.sql
mysql -u root -ppassword < /sql-files/sql-files.sql

the problem is, the entrypoint is run but then just hangs with问题是,入口点已运行,但随后挂起

2022-01-14T15:07:54.809983Z 0 [Note] Event Scheduler: Loaded 0 events
2022-01-14T15:07:54.810442Z 0 [Note] mysqld: ready for connections.
Version: '5.7.36'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

and never moves onto the next step of the bash script.并且永远不会进入 bash 脚本的下一步。 i've tried adding a & to the end so it is run in the background and this doesn't solve the problem.我尝试在末尾添加一个 & 以便它在后台运行,但这并不能解决问题。

has anyone ever come across this issue?有没有人遇到过这个问题? How can i manually run the entrypoint and then execute some commands after.我如何手动运行入口点,然后执行一些命令。

you can start mysql sleeping in the background before mysqld.你可以在mysqld之前启动mysql在后台休眠。 Would this work for you?这对你有用吗?

start_mysql {
    sleep 30
    mysql -u root -ppassword < /data/backups/backup.sql
    mysql -u root -ppassword < /sql-files/sql-files.sql
}

start_mysql &
./entrypoint.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM