Can't import MySql dump via kubectl

10/14/2020

I'm struggling with import dump via kubectl to MySql database running in Kubernetes. There is no error output, but also no data imported.

Here is proof that there is such pod, also dump file on disk root called /database.sql and command.

root@node-1:~# kubectl get pods -n esopa-test | grep mariadb
esopa-test-mariadb-0                    1/1     Running     0          14d
root@node-1:~# ll /database.sql 
-rw-r--r-- 1 root root 4418347 Oct 14 08:50 /database.sql
root@node-1:~# kubectl exec esopa-test-mariadb-0 -n esopa-test -- mysql -u root -proot database < /database.sql 
root@node-1:~# 

Thank you for any advice

-- Mariyo
dump
import
kubectl
kubernetes
mysql

1 Answer

10/14/2020

You can copy files from a pod to node by using kubectl cp command.

To copy files from pod to node syntax is very simple:

kubectl cp <some-namespace>/<some-pod>:<directory-inside-pod> <directory_on_your_node>

So in your use case you can use following command:

kubectl cp esopa-test/esopa-test-mariadb-0:/database.sql <directory_on_your_node>

And to copy files from node to pod you can use:

kubectl cp <directory_on_your_node> esopa-test/esopa-test-mariadb-0:/database.sql 
-- kool
Source: StackOverflow