7
 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?

Lunartist
  • 394
  • 1
  • 3
  • 9

2 Answers2

9

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.

gohm'c
  • 13,492
  • 1
  • 9
  • 16
9

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
Cesar Celis
  • 166
  • 1
  • 4
  • 8