一千萬個為什麽

搜索

如何遞歸復制文件到Kubernetes窗格?



我想遞歸復制文件到Kubernetes窗格

I tried kubectl cp -r

I got: error: unknown shorthand flag: 'r' in -r

將整個目錄遞歸地轉移到一個窗格中的最佳方法是什麽?

轉載註明原文: 如何遞歸復制文件到Kubernetes窗格?

一共有 2 個回答:

kubectl cp by default does recursive copies when given a directory, although it seems to be picky about trailing slashes. If foo is the directory you'd like to copy, simply run

kubectl cp /path/to/foo :/path/in/container/

根據幫助菜單,遞歸選項似乎不存在。

[email protected] ~ $ 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 :/tmp/bar_dir

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

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

  # Copy /tmp/foo from a remote pod to /tmp/bar locally
  kubectl cp /:/tmp/foo /tmp/bar

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

Usage:
  kubectl cp   [options]

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

為了遞歸復制文件,所有文件都可以放在一個目錄中,並且當這個文件夾被復制到pod時,所有文件都被復制: