Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy files from a windows kubernetes pod container

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.

like image 465
hey Avatar asked Feb 04 '20 21:02

hey


People also ask

How do I copy a file from a docker container?

Obtain the name or id of the Docker container. Issue the docker cp command and reference the container name or id. The first parameter of the docker copy command is the path to the file inside the container. The second parameter of the docker copy command is the location to save the file on the host.

How do I transfer files between pods?

If you're using Kubernetes, you may find the need to move files to and from containers running on pods. Before the days of containerization, we would use a tool like SCP (secure copy protocol) to move files to and from remote machines.


1 Answers

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
like image 129
hey Avatar answered Oct 13 '22 17:10

hey