Lunartist
Lunartist

Reputation: 464

'kubectl cp' command doesn't copy the target directory but its contents

 kubectl cp namespace/podname:/path/target .

If I use the instructed command from kubernetes guide, it only copies the contents inside the target directory and omits target itself.
I don't want to use mkdir every time I need to copy.
What's the option?

Upvotes: 9

Views: 24383

Answers (2)

Cesar Celis
Cesar Celis

Reputation: 306

I have a pod under default namespace called ubuntu-pod with a file located at root: /decomission.log and I got the same error:

$ kubectl cp default/ubuntu-pod:/decommission.log decommission.log
tar: Removing leading `/' from member names

The solution was to remove the slash and then I was able to copy the file with no message:

$ kubectl cp default/ubuntu-pod:decommission.log decommission.log
$ ls
decommission.log

Upvotes: 16

gohm'c
gohm'c

Reputation: 15490

Try kubectl cp namespace/podname:/path/target target. Note specify "./target" will receive a warning: "tar: removing leading '/' from member names". Also, ensure your image have tar command or kubectl cp can fail.

Upvotes: 14

Related Questions