6

I have had some difficulties copying files from a kubernetes pod container (windows nodes) to my local linux subsystem on windows 10:

t@11DT:/mnt/c/dev/auto$ kubectl cp a8677:c:\testlog2.txt .
tar: Removing leading drive letter from member names
error: tar contents corrupted
t@11DT:/mnt/c/dev/auto$ kubectl cp a8677:/c/testlog2.txt ./
tar: /c/testlog2.txt: Couldn't find file: No such file or directory
tar: Error exit delayed from previous errors.
t@11DT:/mnt/c/dev/auto$ kubectl cp a8677:c:\testlog2.txt ./
tar: Removing leading drive letter from member names
error: tar contents corrupted
t@11DT:/mnt/c/dev/auto$ kubectl cp a8677:c:/testlog2.txt ./
tar: Removing leading drive letter from member names
error: tar contents corrupted
t@11DT:/mnt/c/dev/auto$ kubectl cp a8677:c:/testlog2.txt ./t2.txt
tar: Removing leading drive letter from member names
error: tar contents corrupted
t@11DT:/mnt/c/dev/auto$ kubectl cp a8677:c:\testlog2.txt ./t2.txt
tar: Removing leading drive letter from member names
error: tar contents corrupted

The file c:\testlog2.txt definitely existed in pod a8677. But how to address c:\testlog2.txt appropriately?


Note:

Some moderators suggested to close this question, as it is a duplicate of How to copy files from kubernetes Pods to local system . The existing question is about how to copy files in general between linux nodes in kubernetes clusters and linux local systems. This information is covered in the Kubernetes documentation (https://kubectl.docs.kubernetes.io/pages/container_debugging/copying_container_files.html).

This question here is specifically about windows containers. It seems to be neither covered in the kubernetes documentation, nor in any other question I found on stackoverflow. Many things that are straightforward in kubernetes linux nodes need a bit extra research for windows nodes.

I therefore do not think it is a duplicate.

hey
  • 2,643
  • 7
  • 29
  • 50
  • 1
    No - updating the post. – hey Feb 06 '20 at 19:30
  • looks to be a limitation now: https://github.com/kubernetes/kubernetes/issues/77310 my workaround is to copy to file to 'current dir', then copy out: 1. do a in container file copy/move (using kubectl exec ); 2. kubectl cp a8677:testlog2.txt . – cyberguest Apr 30 '21 at 14:41

3 Answers3

14

The correct way is, to omit the drive letter:

kubectl cp <pod_name>:filename

for example:

kubectl cp a8677:testlog2.txt ./t2.txt

If the file is inside a subdirectory, the path needs to contain slashes, and no backslashes:

kubectl cp a8677:my/file/path/file.txt ./myfile.txt
hey
  • 2,643
  • 7
  • 29
  • 50
0

you can copy files, just give your log path and file name.

kubectl cp -n namespace pod_name:logs/file_name file_name

Kumar Pankaj Dubey
  • 1,541
  • 3
  • 17
  • 17
0

CHECK THIS!!!

Open a new terminal and run this command

kubectl cp --help

Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace

tar cf - /tmp/foo | kubectl exec -i -n -- tar xf - -C /tmp/bar

Copy /tmp/foo from a remote pod to /tmp/bar locally

kubectl exec -n -- tar cf - /tmp/foo | tar xf - -C /tmp/bar

Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace

kubectl cp /tmp/foo_dir :/tmp/bar_dir

Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container

kubectl cp /tmp/foo :/tmp/bar -c

Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace

kubectl cp /tmp/foo /:/tmp/bar

Copy /tmp/foo from a remote pod to /tmp/bar locally

kubectl cp /:/tmp/foo /tmp/bar

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 07 '23 at 14:59