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
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.
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:
$(kubectl exec <pod-name> [-c <container-name>] -it -- cat <file-path>) > <local-file>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With