I have several files named out1, out2, ... in my Kubernetes container. I want to copy them to my local computer. I am using:

$ kubectl cp pod:/path/out* .

But I am getting an error:

tar: Removing leading `/' from member names
tar: /path/out*: Cannot stat: No such file or directory tar: Exiting with failure status due to previous errors
error: path/out* no such file or directory

How can I use kubectl cp with wildcards?


Wildcard support was added to kubectl cp in the #72641 pull request.

It is merged but only available in Kubernetes v1.14.0. Take a look at the ChangeLog:

Notable Features:
• kubectl supports copying files with wild card (#72641, @dixudx)

However, as stated on the issue #78854 the PR was made without proper tests and the feature is actually broken. The PR to fix the problem (#78928) is open since June, and it's not merged yet.

Although the PR to fix the feature exists, they are also considering removing the support to wildcard copy.

| improve this answer | |

You can do that using this command:

kubectl cp -n [NAMESPACE] [POD_NAME]:/[POD_DIRECTORY]/. .
| improve this answer | |
  • This is not a solution that uses wildcards to copy files. kubectl cp with wildcards was introduced on Kubernetes v1.14. – Eduardo Baitello Mar 28 '19 at 22:01
  • I see, I misunderstood the question, your answer is correct. @EduardoBaitello – cookiedough Mar 28 '19 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.