'Copy files from remote kubernetes pod to unix machine

I want to copy files from remote kubernetes pod(source) to unix machine(target). Source & Target can be two different clusters. Earlier, openshift pods were used, so i have used rsync to copy files.

What would be the right replacement for rsync? Found kubectl is the right one. Is that can be used from two different clusters?

Thanks



Solution 1:[1]

It's not possible to do cluster to cluster copying. As a workaround you can use kubectl cp command to copy files locally and copy the files to destination.

Use this command to copy files from source to destination

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

Refer to this stack case for more information on copying files and this stack case for copying files locally.

Solution 2:[2]

You can use kubectl to copy files to the local machine. The downside is you can connect only the one cluster at the same time.

# Copy /tmp/foo from a remote pod to /tmp/bar locally
kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar
# Switch kubectl context to the another cluster
# Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace
kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar

Maybe also this article can help.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Philip Welz