Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I copy files between pods or between nodes in the kubernetes cluster?

Is this possible inside the kubernetes cluster?

All examples I've found are copying from a local disk to a pod or vice versa, or is the only option to copy from node to node, for example over SSH, SCP or with other utilities?

like image 284
JDev Avatar asked Jul 19 '18 16:07

JDev


2 Answers

It's not possible to do cluster to cluster copying. You'd need to use kubectl cp to copy it locally, then copy the file back:

kubectl cp <pod>:/tmp/test /tmp/test
kubectl cp /tmp/test <pod>:/tmp/test

If you are trying to share files between pods, and only one pods needs write access, you probably want to mount an ro volume on multiple pods, or use an object store like S3. Copying files to and from pods really shouldn't be something you're doing often, that's an anti-pattern

like image 162
jaxxstorm Avatar answered Oct 23 '22 14:10

jaxxstorm


Check out this article.

In short, this is the command:

kubectl exec pod-01 -- tar cf - /dir1 /dir2 | kubectl exec -i pod-02 -- tar xvf - -C /
like image 1
Miroslav Makarov Avatar answered Oct 23 '22 13:10

Miroslav Makarov