How to copy a file from container to container in a specific namespace?

Let's say I have my-namespace β†’ my-pod β†’ my-container and I have a file located in my container: /opt/tomcat/logs/catalina.2017-05-02.log. I applied the following command to copy a file that does not work,

kubectl cp my-namepace/my-pod:/opt/tomcat/logs/catalina.2017-05-02.log -c my-container . 

Note. I have a tar binary in the container

Error:

 tar: Removing leading `/' from member names error: open .: is a directory 
+21
source share
8 answers

this works for me:

 $(kubectl exec <pod-name> [-c <container-name>] -it -- cat <file-path>) > <local-file> 
+18
source

What you are asking kubectl to do is copy the catalina.2017-05-05-02.log file into the current context, but the current context is the directory. The error is that you cannot copy the file to have a directory name.

Try specifying the copied version of the file:

kubectl cp my-namepace/my-pod:/opt/tomcat/logs/catalina.2017-05-02.log -c my-container ./catalina.2017-05-02.log .

+34
source

I noticed that it crashes when you try to specify a namespace (both as a prefix to the module identifier and using -n ). Using one module id works for me:

 kubectl cp postgres-1111111111-11abc:/tmp/dump.csv dump 
+3
source

The following kubectl cp NameSpace/POD_NAME: /DIR/FILE_NAME/tmp/ works for me.

+2
source

I found this use most convenient for me

 kubectl cp /tmp/file <your_namespace>/<your_pod>:/tmp/newfile 

and another direction

 kubectl cp <your_namespace>/<your_pod>:/tmp/file /tmp/newfile 
+1
source

I just want to confirm that the command - kubectl cp - does not work as described in the documentation. I use both namespace and container.

0
source

Remove the "/" after ":" when specifying the container file.

So it

 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 . 
0
source

Destination must also be a file name. So the team should be

 kubectl cp my-namepace/my-pod:/opt/tomcat/logs/catalina.2017-05-02.log -c my-container ./catalina.2017-05-02.log 

The "cat" command works well for ascii files. there will be restrictions for other files, and the copied files may be damaged.

0
source

All Articles