I often want to have some database dumps from my mongo also in my local Setup. To achieve this is pretty easy.
You can either copy files or whole folders.
What we need is the kubectl command line tool.
Copy Files from a pod to your machine
kubectl cp {{namespace}}/{{podname}}:path/to/directory /local/path
eg:
kubectl cp mongo-0:/dump /local/dump
Copy Files to a pod
kubectl cp /local/path namespace/podname:path/to/directory
eg:
kubectl cp /local/dump mongo-0:/dump
The amazing hint on this is, this works as well with docker.
Just change kubectl to docker and it will work as well.
Copy Files from a docker container to your machine
docker cp containerID:/path/to/directory /local/path
eg:
docker cp mongo-0:/dump /local/dump
Copy Files to a docker container
docker cp /local/path containerID:path/to/directory
eg:
docker cp /local/dump mongo-0:dump
Why i write this obvious post? I'm tiered looking up the correct syntax now and then and just looking at my blog post speed things up.
Top comments (4)
Awesome and simple! Works perfectly in OpenShift as well ("oc cp ....").
when files is copied to pod, pod gets restarted.
could not understand the problem
any idea?
It is possible that the pod is running out of disk space. What do the logs say? You can check the logs with this command.
How to do the same via code with "@kubernetes/client-node" i.e., the official Kubernetes client library for javascript.
github.com/kubernetes-client/javas...