简体   繁体   中英

running mysql in a kubernetes init container

I am running mysql as an init container for a kubernetes deployment.

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.

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.

So i cant just dump the dump.sql in docker-entrypoint-initdb.d and be done with it.

This is because the volumesnapshot kubernetes resources would be taken before the data is restored/ready. 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)

So far i have this bash script which is run on the container startup.

./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. 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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