How to copy file from container in a pod in a specific namespace?
Source and Destination file name should be same, the below command worked for me:
kubectl cp namespace/pod-name:abc.log .\Desktop\abc.log
this works for me:
$(kubectl exec <pod-name> [-c <container-name>] -it -- cat <file-path>) > <local-file>
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
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
.