场景1,
emambp:static-html ema$ kubectl cp index-kubernetes.html learnci/performance-ap564-xr952:/usr/share/nginx/html
Defaulting container name to retrieve-instance-data.
^[[Atar: index-kubernetes.html: Cannot open: Permission denied
tar: Exiting with failure status due to previous errors
command terminated with exit code 2
emambp:static-html ema$ kubectl cp index-kubernetes.html learnci/performance-ap564-xr952:/usr/share/nginx/html/
Defaulting container name to retrieve-instance-data.
kubectl cp 不需要使用-n 指定namespace 但需要copy的目标路径 显示指出 哪个namespace/哪个pod:目录
切记 目标路径必须是目录"/"结尾
场景2,
从pod内部copy文件到本地文件系统
emambp:tian ema$ kubectl version
Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.2", GitCommit:"bdaeafa71f6c7c04636251031f93464384d54963", GitTreeState:"clean", BuildDate:"2017-10-24T19:48:57Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:25:46Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
当前kubectl 客户端版本 服务器版本
几种错误的做法:
emambp:tian ema$ pwd
/Users/ema/work/bb_cicd/starter/kubernetes/tian
emambp:tian ema$ kubectl cp learn-deployments/lrn145033-learn-tomca7956c-g9k8q:/usr/local/blackboard/logs/bb-email-log.txt ./
Defaulting container name to learn.
tar: Removing leading `/' from member names
error: open .: is a directory
emambp:tian ema$ kubectl cp learn-deployments/lrn145033-learn-tomca7956c-g9k8q:/usr/local/blackboard/logs/bb-email-log.txt /Users/ema/work/bb_cicd/starter/kubernetes/tian
Defaulting container name to learn.
tar: Removing leading `/' from member names
error: open /Users/ema/work/bb_cicd/starter/kubernetes/tian: is a directory
emambp:tian ema$ kubectl cp learn-deployments/lrn145033-learn-tomca7956c-g9k8q:/usr/local/blackboard/logs/bb-email-log.txt /Users/ema/work/bb_cicd/starter/kubernetes/tian/
Defaulting container name to learn.
tar: Removing leading `/' from member names
error: open /Users/ema/work/bb_cicd/starter/kubernetes/tian: is a directory
emambp:tian ema$ kubectl cp learn-deployments/lrn145033-learn-tomca7956c-g9k8q:bb-email-log.txt /Users/ema/work/bb_cicd/starter/kubernetes/tian/
Defaulting container name to learn.
error: open /Users/ema/work/bb_cicd/starter/kubernetes/tian: is a directory
需求:想从pod内部 目录 /usr/local/blackboard/logs/ 下的文件bb-email-log.txt copy到本地文件系统 这个目录下 /Users/ema/work/bb_cicd/starter/kubernetes/tian/
源目录是pod 目录时,:后只能跟文件名,不能是以/ 开头的路径,所以需要先用kubectl exec ssh到pod上,copy文件到工作目录下workdir, (此example种workdir为 /home/bbuser)
emambp:tian ema$ kubectl -n learn-deployments exec -it lrn145033-learn-tomca7956c-g9k8q -- /bin/bash
Defaulting container name to learn.
Use 'kubectl describe pod/lrn145033-learn-tomcat-5c69c7956c-g9k8q' to see all of the containers in this pod.
bbuser@lrn145033-learn-tom7956c-g9k8q:~$ cp /usr/local/blackboard/logs/bb-email-log.txt .
bbuser@lrn145033-learn-tom7956c-g9k8q:~$ pwd
/home/bbuser
bbuser@lrn145033-learn-tomca7956c-g9k8q:~$ ls
bb-email-log.txt bin learn-installer learn-installer.properties
bbuser@lrn145033-learn-tomca7956c-g9k8q:~$
emambp:tian ema$ kubectl cp learn-deployments/lrn145033-learn-tom7956c-g9k8q:bb-email-log.txt /Users/ema/work/bb_cicd/starter/kubernetes/tian/
Defaulting container name to learn.
error: open /Users/ema/work/bb_cicd/starter/kubernetes/tian: is a directory
目标参数必须为文件 不能是一个目录
解决,
emambp:tian ema$ kubectl cp learn-deployments/lrn145033-learn-tom7956c-g9k8q:bb-email-log.txt /Users/ema/work/bb_cicd/starter/kubernetes/tian/bb-email-log.txt
总结:
源参数 不能是以“/” 开头的,所以可以把需要copy的文件先拷贝到pod的工作目录下
目标参数必须为文件 不能是目录