Search code examples
kubectlazure-aksrsync

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

  • 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.