2

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

1

2 Answers 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.

1
  • Thanks. how to handle in production scenario? It should be done without moving to local system
    – Cdr
    Commented May 18, 2022 at 7:15
2

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.

2
  • Thanks. how to handle in production scenario? It should be done without moving to local system.
    – Cdr
    Commented May 17, 2022 at 15:53
  • As @Philip Welz said, you can connect only to one cluster at the same time. Commented May 20, 2022 at 13:58

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.