1

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

Raja
  • 507
  • 1
  • 6
  • 24
  • 1
    Does this answer your question? [How to copy files from kubernetes Pods to local system](https://stackoverflow.com/questions/52407277/how-to-copy-files-from-kubernetes-pods-to-local-system) – Ivan Aracki May 17 '22 at 12:19

2 Answers2

1

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.

Philip Welz
  • 2,449
  • 5
  • 12
  • Thanks. how to handle in production scenario? It should be done without moving to local system – Raja May 18 '22 at 07:15
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.

Goli Nikitha
  • 858
  • 3
  • 9