kubectl cp 命令使用bash
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.
app
# 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
ui
# 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>
url
# 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
spa
# Copy /tmp/foo from a remote pod to /tmp/bar locally
kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar
.net
Options:
-c, --container='': Container name. If omitted, the first container in the pod will be chosen
--no-preserve=false: The copied file/directory's ownership and permissions will not be preserved in the container
blog
Usage:
kubectl cp <file-spec-src> <file-spec-dest> [options]
ip
出處:https://www.cnblogs.com/liucx/ci
前提:在容器裏須要安裝tar命令:
[root@k8s-master ~]# kubectl exec -it cloud-786d84c554-p7jz7 /bin/bash
bash-4.2# yum -y install tar
rem
從Pod容器中copy文件至本地
kubectl cp -c cloud-loan-gate uat/cloud-786d84c554-p7jz7:app/logs/app/cloud.log cloud.log注:uat:爲namespace-c :指定容器(因pod中有多個container,默認從第一個,有可能報錯找不到文件和目錄)源目錄參數時,:後只能跟文件名,不能是以「/」開頭的路徑(eg:app/logs/cloud.log)目標參數時,必須爲文件不能是一個目錄(eg:cloud.log)