Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

kubernetes

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 
like image 381
zillani Avatar asked May 02 '17 07:05

zillani


People also ask

Can pods communicate between namespaces?

Namespaces are used to isolate resources within the control plane. For example if we were to deploy a pod in two different namespaces, an administrator running the “get pods” command may only see the pods in one of the namespaces. The pods could communicate with each other across namespaces however.


2 Answers

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.

like image 69
Simon I Avatar answered Oct 11 '22 16:10

Simon I


this works for me:

$(kubectl exec <pod-name> [-c <container-name>] -it -- cat <file-path>) > <local-file> 
like image 43
Gregory Patmore Avatar answered Oct 11 '22 16:10

Gregory Patmore