How do I restore a dump file from mysqldump using kubernetes? How do I restore a dump file from mysqldump using kubernetes? kubernetes kubernetes

How do I restore a dump file from mysqldump using kubernetes?


As described in here you can use the following command to restore a DB on kubernetes pod from a dump in your machine

$ kubectl exec -it {{podName}} -n {{namespace}} -- mysql -u {{dbUser}} -p{{password}} {{DatabaseName}} < <scriptName>.sqlExample :$ kubectl exec -it mysql-58 -n sql -- mysql -u root -proot USERS < dump_all.sql


What I did was this:

  • Create an NFS mount with two sub0drectories: mysql and initd.
  • In initd, I added several ,sql files, including the dump.
  • Mount initd as /docker-entrypoint-initdb.d in the deployment.This causes all the files to be read at initialisation time provided that it is the first time we run.
  • The mysql directory is mounted as /var/lib/mysql and contains all the mariaDB files.

If I need to revert, I trash all the contents of the mysql directory and re-create the deployment.


This should work:

kubectl  --kubeconfig=k8s-XXXXXXX-kubeconfig.yaml exec -i ddevdb-XXXXX -- mysql -u root -h mysqlservice -proot drupal < you-dump.sql

kubeconfig is optional, digitalocean for examples provides that so you can run your commands from your local.

To see if everything looks good:

kubectl --kubeconfig=k8s-XXXXXXX-kubeconfig.yaml run -it --rm --image=mariadb:10.4 --restart=Never mysql -- mysql -h mysqlservice -proot

After which you'll have a terminal inside mysql.