How to copy files from a windows kubernetes pod container

2/4/2020

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
kubernetes
windows

1 Answer

2/4/2020

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
Source: StackOverflow