kubernetes/kubernetes

kubectl cp a file from a Windows Pod to Windows 11 localhost failed

GoingMyWay opened this issue · 9 comments

What happened?

I was trying to cp a from a Windows Pod to the Windows localhost. But it failed.

kubectl.exe cp --kubeconfig .\kubconfig -n namespace-win pod-20240509-120334-779546rrfsc:C:\\data\\0509-1065.log 0509-1065.log

It showed

tar: Removing leading drive letter from member names
error: tar contents corrupted

What did you expect to happen?

I want to copy the file to the localhost.

How can we reproduce it (as minimally and precisely as possible)?

Windows 11 localhost
Windows Pod.

Anything else we need to know?

No response

Kubernetes version

$(powershell) kubectl version
# paste output here

Client Version: v1.29.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Unable to connect to the server: dial tcp 127.0.0.1:6443: connectex: No connection could be made because the target machine actively refused it.

Cloud provider

OS version

# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here

BuildNumber  Caption                      OSArchitecture  Version
22621        Microsoft Windows 11 Professional  64-bit          10.0.22621

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, ...) and versions (if applicable)

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

/sig windows

Try this way
kubectl.exe cp --kubeconfig .\kubconfig -n namespace-win pod-20240509-120334-779546rrfsc:C:/data/0509-1065.log
./0509-1065.log

Try this way kubectl.exe cp --kubeconfig .\kubconfig -n namespace-win pod-20240509-120334-779546rrfsc:C:/data/0509-1065.log ./0509-1065.log

@tamilselvan1102 It failed. It shows

tar: Removing leading drive letter from member names
error: tar contents corrupted

I think you might be running into this:

// All the files will start with the prefix, which is the directory where
// they were located on the pod, we need to strip down that prefix, but
// if the prefix is missing it means the tar was tempered with.
// For the case where prefix is empty we need to ensure that the path
// is not absolute, which also indicates the tar file was tempered with.
if !strings.HasPrefix(header.Name, prefix) {
return fmt.Errorf("tar contents corrupted")
}

This is probably the cause:

tar: Removing leading drive letter from member names

Is there a way you can do this without referencing the drive letter, like maybe this way?
See comments here for some ideas:
kubernetes/kubectl#1225 (comment)
kubernetes/kubectl#1225 (comment)

I wonder if something like this would work...

kubectl.exe cp --kubeconfig .\kubconfig -n namespace-win pod-20240509-120334-779546rrfsc:\\.\c\\data\0509-1065.log 0509-1065.log

I think you might be running into this:

// All the files will start with the prefix, which is the directory where
// they were located on the pod, we need to strip down that prefix, but
// if the prefix is missing it means the tar was tempered with.
// For the case where prefix is empty we need to ensure that the path
// is not absolute, which also indicates the tar file was tempered with.
if !strings.HasPrefix(header.Name, prefix) {
return fmt.Errorf("tar contents corrupted")
}

This is probably the cause:

tar: Removing leading drive letter from member names

Is there a way you can do this without referencing the drive letter, like maybe this way? See comments here for some ideas: kubernetes/kubectl#1225 (comment) kubernetes/kubectl#1225 (comment)

I wonder if something like this would work...

kubectl.exe cp --kubeconfig .\kubconfig -n namespace-win pod-20240509-120334-779546rrfsc:\\.\c\\data\0509-1065.log 0509-1065.log

@brianpursley

I tried it and it showed the following error:

tar: : Couldn't visit directory: No such file or directory
tar: Error exit delayed from previous errors.

or

tar: 6.0.1: Couldn't visit directory: No such file or directory
tar: Error exit delayed from previous errors.

Gotta get the slashes right. Your original path had double-backslashes and I think I skipped removing one of them. The \\ before the . is supposed to be double though (Windows 🤷‍♂️)

Try this:

kubectl.exe cp --kubeconfig .\kubconfig -n namespace-win pod-20240509-120334-779546rrfsc:\\.\c\data\0509-1065.log 0509-1065.log

Otherwise, I'm out of ideas.

Gotta get the slashes right. Your original path had double-backslashes and I think I skipped removing one of them. The \\ before the . is supposed to be double though (Windows 🤷‍♂️)

Try this:

kubectl.exe cp --kubeconfig .\kubconfig -n namespace-win pod-20240509-120334-779546rrfsc:\\.\c\data\0509-1065.log 0509-1065.log

Otherwise, I'm out of ideas.

@brianpursley Still the same error. Thanks. It is not easy to use k8s on Windows.