Reputation: 1090
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
Upvotes: 45
Views: 75646
Reputation: 60084
I tried all the given options here above it resolve the error but the warning still appears.
tar: Removing leading `/' from member names
BTW the copied file still okay just the warning is a bit confusing.
If you are using absolute path kubectl cp namespace/pod:/somepath/somfile somepath/somefile
will print the same warning
So if the file is in the working directory of the container the remove the abosulte path and the warning will disappear.
k cp "default/name-redis-6d66b898d6-8xdkb:dump.rdb" ./dump.rdb
Upvotes: 2
Reputation: 81
Source and Destination file name should be same, the below command worked for me:
kubectl cp namespace/pod-name:abc.log .\Desktop\abc.log
Upvotes: 8
Reputation: 31
Destination should also be a filename. so, command should be
kubectl cp my-namepace/my-pod:/opt/tomcat/logs/catalina.2017-05-02.log -c my-container ./catalina.2017-05-02.log
"cat" command works well for ascii files. for other files there would be limitations and copied files might be corrupted.
Upvotes: 3
Reputation: 1744
Remove "/" after ":" when specifying container file.
So this
kubectl cp my-namepace/my-pod:/opt/tomcat/logs/catalina.2017-05-02.log -c my-container .
will turn into this:
kubectl cp my-namepace/my-pod:opt/tomcat/logs/catalina.2017-05-02.log -c my-container .
Upvotes: 2
Reputation: 757
Following command kubectl cp NameSpace/POD_NAME:/DIR/FILE_NAME /tmp/
works for me.
Upvotes: 4
Reputation: 3231
I found this usage the most convenient for me
kubectl cp /tmp/file <your_namespace>/<your_pod>:/tmp/newfile
and other direction
kubectl cp <your_namespace>/<your_pod>:/tmp/file /tmp/newfile
Upvotes: 3
Reputation: 6649
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:
kubectl cp postgres-1111111111-11abc:/tmp/dump.csv dump
Upvotes: 5
Reputation: 1164
this works for me:
$(kubectl exec <pod-name> [-c <container-name>] -it -- cat <file-path>) > <local-file>
Upvotes: 30
Reputation: 3586
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
.
Upvotes: 55