我想将文件递归复制到Kubernetes容器中

我尝试了kubectl cp -r

我得到了:
error: unknown shorthand flag: 'r' in -r

什么是最好的方法将整个目录递归地传输到pod中。

#1 楼

默认情况下,给定目录时,kubectl cp会进行递归复制,尽管对于尾部的斜杠似乎有些挑剔。如果foo是您要复制的目录,只需运行

kubectl cp /path/to/foo <pod-id>:/path/in/container/


评论


获胜时:kubectl cp C:/ myfiles / azureCLI / WantToCopy / * my-pod:/ mnt / data / something /

– TiloBunt
18-09-7在23:14

#2 楼

根据帮助菜单,似乎没有递归选项。

user@localhost ~ $ kubectl cp --help
Copy files and directories to and from containers.

Examples:
  # !!!Important Note!!!
  # Requires that the 'tar' binary is present in your container
  # image.  If 'tar' is not present, 'kubectl cp' will fail.

  # Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
  kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir

  # Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
  kubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>

  # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
  kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar

  # Copy /tmp/foo from a remote pod to /tmp/bar locally
  kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar

Options:
  -c, --container='': Container name. If omitted, the first container in the pod will be chosen

Usage:
  kubectl cp <file-spec-src> <file-spec-dest> [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).


为了递归复制文件,所有文件都可以放在目录中,当文件夹已复制到pod,所有文件均已复制: