想从k8s的pod中拷贝文件到宿主机,kubectl 的cp命令,但是网上搜索了下,感觉有点乱,自己记录下。

    hadoop这个namespace下,有个hadoop-hadoop-yarn-rm-0的pod,它的work_dir是/usr/local/hadoop,在这个目录下有个application_1564318400358_0562_1文件,现在的目的是将此文件拷贝到宿主机上,命令如下List-1所示。由于我们的work_dir是/usr/local/hadoop,所以不需要写完全路径/usr/local/hadoop/application_1564318400358_0562_1,写完全路径反而会报错

    List-1

kubectl cp -n hadoop hadoop-hadoop-yarn-rm-0:application_1564318400358_0562_1 ./

    如下List-2中报错

    List-2

[~]$ kubectl cp -n hadoop hadoop-hadoop-yarn-rm-0:/usr/local/hadoop/application_1564318400358_0562_1 ./
tar: Removing leading `/' from member names
[~]$ kubectl cp -n hadoop hadoop-hadoop-yarn-rm-0:usr/local/hadoop/application_1564318400358_0562_1 ./
error: usr/local/hadoop/application_1564318400358_0562_1 no such file or directory


实例操作:
[root@pressure-pretest-master03 ~]# kubectl cp -n xitu-pressure h5-web-pressure-8498f76b59-mnm66:/var/log/nginx/access.log ./
tar: removing leading '/' from member names
[root@pressure-pretest-master03 ~]# ls
                   
access.log             



[root@pressure-pretest-master03 ~]# tar -czvf access.log.tar.gz access.log 
access.log
[root@pressure-pretest-master03 ~]# ls
                  
access.log            
access.log.tar.gz      

  

 

转载于:https://www.cnblogs.com/weifeng1463/p/11360774.html

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐