您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
42.存储 Volume(2)
发布时间:2023-01-01 19:52:39编辑:雪饮阅读()
Step1
先清理下pod
kubectl delete pod –all
然后master、node01、node02都同步下时间
ntpdate ntp1.aliyun.com
集群的时间同步其实是很重要的
然后创建这次的环境目录并进入
[root@k8s-master01 reg]# cd ..
[root@k8s-master01 ~]# mkdir volume
[root@k8s-master01 ~]# cd volume
然后创建空目录卷挂载的pod
[root@k8s-master01 volume]# cat em.yaml
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: hub.atguigu.com/library/myapp:v2
name: test-container
volumeMounts:
- mountPath: /cache
name: cache-volume
volumes:
- name: cache-volume
emptyDir: {}
[root@k8s-master01 volume]# kubectl apply -f em.yaml
pod/test-pd created
这里我们挂载于pod里的/cache目录中
那么这个结果也就是正常的了
[root@k8s-master01 volume]# kubectl exec test-pd -it -- /bin/sh
/ # ls /cache
/ #
Step2
同样先清理下pod
[root@k8s-master01 volume]# kubectl delete pod --all
pod "test-pd" deleted
然后咱们创建一个包含多个容器的pod
[root@k8s-master01 volume]# cat pod1.yaml
apiVersion: v1
kind: Pod
metadata:
name: test-pd1
spec:
containers:
- image: hub.atguigu.com/library/myapp:v2
name: test-container
volumeMounts:
- mountPath: /cache
name: cache-volume
- name: liveness-exec-container
image: busybox
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","sleep 6000s"]
volumeMounts:
- mountPath: /test
name: cache-volume
volumes:
- name: cache-volume
emptyDir: {}
[root@k8s-master01 volume]# kubectl apply -f pod1.yaml
pod/test-pd1 created
进入pod第一个容器的挂载点可以看到是没有内容的空目录
[root@k8s-master01 volume]# kubectl exec test-pd1 -c test-container -it -- /bin/sh
/ # ls /cache
/ #
另外开一个master的会话进入pod第二个容器中对应挂载点看到也是没有内容的空目录
[root@k8s-master01 ~]# kubectl exec test-pd1 -c liveness-exec-container -it -- /bin/sh
/ # ls /test
然后第一个会话处新增一个文件于其挂载点路径中
/ # date > /cache/index.html
/ # ls /cache
index.html
/ # cat /cache/index.html
Sun Jan 1 11:44:16 UTC 2023
那么第二个会话出也能看到自己挂载点路径中多了第一个会话刚才新增的这个文件及内容
/ # ls /test
index.html
/ #
/ # cat /test/index.html
Sun Jan 1 11:44:16 UTC 2023
然后第二个会话在第一个会话创建的文件中覆盖了内容并新增了内容
/ # date > /test/index.html
/ # date >> /test/index.html
/ # cat /test/index.html
Sun Jan 1 11:50:15 UTC 2023
Sun Jan 1 11:50:23 UTC 2023
同样的第一个会话也可以看到自己之前新增的文件中的内容被覆盖了且新增了新的内容
/ # cat /cache/index.html
Sun Jan 1 11:50:15 UTC 2023
Sun Jan 1 11:50:23 UTC 2023
关键字词:存储,Volume
上一篇:40、存储 Secret(2)
下一篇:43、存储 Volume(3)