'kubectl cp' 命令不复制目标目录,而是复制其内容

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

 kubectl cp namespace/podname:/path/target .

如果我使用 kubernetes 指南中的指示命令,它只会复制 target 目录中的内容并忽略 target 本身。
我不想每次需要复制时都使用mkdir
选项是什么?

尝试kubectl cp namespace/podname:/path/target target。注意指定“./target”将收到警告:“tar:从成员名称中删除前导‘/’”。另外,请确保您的图像有 tar 命令,否则 kubectl cp 可能会失败。