【问题标题】:How to use tar command options when calling kubectl cp command调用 kubectl cp 命令时如何使用 tar 命令选项
【发布时间】:2020-01-16 20:12:40
【问题描述】:

似乎kubectl cp 命令在后台使用tar 命令。我如何使用(通过kubectl cp 命令传递它们)一些tar 命令选项,例如--exclude?例如,这可能有助于排除不需要从容器中复制的特定文件/目录。

谢谢

【问题讨论】:

    标签: kubernetes copy tar options kubectl


    【解决方案1】:

    你可以这样做 -

    kubectl exec -n <some-namespace> <some-pod> -- tar cf - --exclude='pattern' /tmp/foo | tar xf - -C /tmp/bar
    

    例如-

    我在命名空间“pankaj”中运行了一个 pod;在我的容器中,我在路径中有 2 个文件 - /tmp/foo

    /tmp/foo # ls
    file1.txt  file2.txt
    

    我的用途是我只想复制文件 file1.txt 所以我会这样做 -

    kubectl exec -n pankaj <pod name> -- tar cf - --exclude='file2.txt' tmp/foo | tar xf - -C /Users/pa357856/test
    

    结果是我只会得到 file1.txt

    $ pwd
    /Users/pa357856/test
    $ ls tmp/foo/
    file1.txt
    

    【讨论】:

    • 谢谢,最好将它作为kubectl cp 选项的一部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 1970-01-01
    • 2017-12-29
    相关资源
    最近更新 更多