How to copy files from kubernetes Pods to local system

后端 未结 10 1655
暖寄归人
暖寄归人 2020-12-24 10:22

I\'m trying to copy files from Kubernetes Pods to my local system. I am getting the below error while running following command:

kubectl cp aks-ssh2-6cd4948         


        
10条回答
  •  忘掉有多难
    2020-12-24 11:07

    The command in the question posted is absolutely right. As answered before this particular issue seems to be missing tar in the container. I actually did not know it was needed, but confirmed that the pod has it:

    # find / -name tar
    /bin/tar
    /usr/lib/mime/packages/tar
    /usr/share/doc/tar
    

    My error was using . to copy to the current directory (works with cp and scp) because it needs the full path, as shown in the original question:

    kubectl cp pod-name-shown-in-get-pods:/path/to/filename /local/dir/filename
    

    But not:

    kubectl cp pod-name-shown-in-get-pods:/path/to/filename .
    

    Which gives:

    error: open .: is a directory
    tar: Removing leading `/' from member names
    

    Now the tar in the error message makes sense!

提交回复
热议问题