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

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


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


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 /


Here's a way to copy from inside your container to your local machine:

kubectl cp <file-spec-src> <file-spec-dest>

example

kubectl cp your-pod:/path/to/file /local/pathkubectl cp /local/path your-pod:/path/to/file