- Yair Mark
Today I had to copy some files and folders off of a Kubernetes pod. I wanted to copy them to the current directory I was in. Normally on Linux you would do this using a command similar to
cp -r path/to/someFolder .. After doing a bit of investigation I found that
kubectl does have the
cp option so I promptly tried to copy the folder I wanted:
kubectl cp yourNameSpace/the-pod-you-want-59595688cc-btlvt:/path/on/pod/to/desiredFolder/ .
But this gave me the following error:
error: open .: is a directory
Based on this error it looks like kubectl is trying to copy the folder across to my local machine and name it
.. It is unable to name it this as dot is the current directory on *nix systems. Instead you have to change your command to something like the below:
kubectl cp yourNameSpace/the-pod-you-want-59595688cc-btlvt:/path/on/pod/to/desiredFolder/ desiredFolder
This will copy
desiredFolder from the pod to the current directory to a folder also called
desiredFolder. You are not forced to name the target folder this - you can call it whatever you want. Another important thing to note is that you do not need and cannot use a
-r flag for folders like with the
cp command. Copying files is identical to the above you simply specify the path to the file and not a folder and then give a name for the target when it is copied.