pod资源共享实现机制_共享存储

 

 共享存储:

apiVersion: v1
kind: Pod
metadata:
labels:
app: test
name: pod-volume-test
namespace: default
spec:
containers:
- image: busybox
name: test
command: ["/bin/sh","-c","sleep 12h"]
volumeMounts:
- name: log
mountPath: /data
- image: nginx
name: web
volumeMounts:
- name: log
mountPath: /usr/share/nginx/html
volumes:
- name: log
emptyDir: {}

测试共享存储步骤如下:

登录容器命令:kubectl exec -it pod-volume-test -c web -- sh;kubectl exec -it pod-volume-test -c test -- sh

登录容器web:cd /usr/share/nginx/html;touch a.txt

登录容器test:cd /data;ls能看到a.txt

登录容器test:cd data;touch b.txt

登录容器web:cd /usr/share/nginx/html;ls能看到.b.txt

共享网络:
apiVersion: v1
kind: Pod
metadata:
labels:
app: test
name: pod-net-test
namespace: default
spec:
containers:
- image: busybox

name: test
command: ["/bin/sh","-c","sleep 12h"]
- image: nginx
name: web

测试共享网络步骤如下:

登录容器命令:kubectl exec -it pod-net-test -c web -- sh;kubectl exec -it pod-net-test -c test -- sh

登录test容器:运行netstat -na能看到80端口,这证明web容器的nginx端口能被test容器看到

登录test容器:wget 127.0.0.1:80看到web容器的nginx页面

登录web容器:cd /usr/share/nginx/html;echo 666 > index.html

登录test容器:wget 127.0.0.1:80看到666页面

 

查看共享网络的基础容器:

kubectl get pod -o wide

pod资源共享实现机制_共享存储_02

 

 发现pod在node-2,所以登录node-2查看:

pod资源共享实现机制_web容器_03