Say I have, my-namespace -> my-pod -> my-container and I have a file located at my-container:/opt/tomcat/logs/catalina.2017-05-02.log. I have applied the below command to copy the file which isn't working,
kubectl cp my-namepace/my-pod:/opt/tomcat/logs/catalina.2017-05-02.log -c my-container .
Note: I have the tar binary on my container
Error:
tar: Removing leading `/' from member names
error: open .: is a directory
I found this usage the most convenient for me
and other direction
What you are asking
kubectl
to do is copy the file catalina.2017-05-02.log to the current context, but the current context is a directory. The error is stating that you can not copy a file to have the name of a directory.Try giving the copied version of the file a name:
kubectl cp my-namepace/my-pod:/opt/tomcat/logs/catalina.2017-05-02.log -c my-container ./catalina.2017-05-02.log
.this works for me:
Following command
kubectl cp NameSpace/POD_NAME:/DIR/FILE_NAME /tmp/
works for me.I noticed it fails when you try to specify the namespace (both as a prefix to the pod identifier and by using
-n
option) Using the pod identifier alone works for me:Remove "/" after ":" when specifying container file.
So this
will turn into this: