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