Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoingMyWay opened this issue May 10, 2024 · 8 comments
Open

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

GoingMyWay opened this issue May 10, 2024 · 8 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/windows Categorizes an issue or PR as relevant to SIG Windows.

Comments

@GoingMyWay
Copy link

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)

@GoingMyWay GoingMyWay added the kind/bug Categorizes issue or PR as related to a bug. label May 10, 2024
@k8s-ci-robot k8s-ci-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label May 10, 2024
@k8s-ci-robot
Copy link
Contributor

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.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label May 10, 2024
@tamilselvan1102
Copy link

/sig windows

@k8s-ci-robot k8s-ci-robot added sig/windows Categorizes an issue or PR as relevant to SIG Windows. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 10, 2024
@tamilselvan1102
Copy link

tamilselvan1102 commented May 10, 2024

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

@GoingMyWay
Copy link
Author

GoingMyWay commented May 13, 2024

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

@brianpursley
Copy link
Member

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

@GoingMyWay
Copy link
Author

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.

@brianpursley
Copy link
Member

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.

@GoingMyWay
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/windows Categorizes an issue or PR as relevant to SIG Windows.
Projects
Status: No status
Development

No branches or pull requests

4 participants