kubectl管理kubernetes集群(2)

exec:
[root@master ~]# kubectl exec mysql-2261771434-r8td1 ls
[root@master ~]# kubectl exec -it mysql-2261771434-r8td1 bash
bash-4.2#
cp:
[root@master ~]# kubectl cp mysql-2261771434-r8td1:/tmp/hosts /etc/hosts
error: unexpected EOF

[root@master ~]# kubectl cp --help
Examples:
  # !!!Important Note!!!
  # Requires that the 'tar' binary is present in your container  使用kubectl cp 你的容器实例中必须有tar命令,如果没有的话就会失败
  # image.  If 'tar' is not present, 'kubectl cp' will fail.
[root@master ~]# kubectl exec -it mysql-2261771434-r8td1 bash
bash-4.2# yum install tar net-tools -y 

bash-4.2# echo 'this is test' > /tmp/test.txt

再次测试:

拷贝出来

[root@master ~]# kubectl cp mysql-2261771434-r8td1:/tmp/test.txt /opt/test.txt
[root@master ~]# more /opt/test.txt
this is test

拷贝回去:

[root@master ~]# echo "this is out" >> /opt/test.txt

[root@master ~]# kubectl cp /opt/test.txt mysql-2261771434-r8td1:/tmp/test.txt

[root@master ~]# kubectl exec -it mysql-2261771434-r8td1 bash
bash-4.2# cat /tmp/test.txt
this is test

this is out

kubectl attach:

用户取得pod中容器的实时信息,可以持续不断实时的取出信息。类似于tail -f

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/4ae6b4aba8cc6606d48d4325abbf04a2.html