Kubernetes部分Volume类型介绍及yaml示例--emptyDir
时间:2018-06-05 16:21:35
收藏:0
阅读:1669
Kubernetes部分Volume类型介绍及yaml示例--emptyDir(本地数据卷)
- 说明
EmptyDir类型的volume创建于pod被调度到某个宿主机上的时候,而同一个pod内的容器都能读写EmptyDir中的同一个文件。一旦这个pod离开了这个宿主机,EmptyDir中的数据就会被永久删除。所以目前EmptyDir类型的volume主要用作临时空间,比如Web服务器写日志或者tmp文件需要的临时目录。 - 实战使用共享卷的标准单容器POD
#创建yaml文件 cat >> emptyDir.yaml << EOF apiVersion: v1 kind: Pod metadata: labels: name: test-emptypath role: master name: test-emptypath namespace: test spec: containers: - name: test-emptypath image: nginx:1.7.9 volumeMounts: - name: log-storage mountPath: /tmp/ volumes: - name: log-storage emptyDir: {}#启动emptyDir.yaml kubectl create -f ./emptyDir.yaml#查看Pod运行状态 kubectl get po -n test NAME READY STATUS RESTARTS AGE test-emptypath 1/1 Running 0 3h ##说明:当 Pod 被分配给节点时,首先创建 emptyDir 卷,并且只要该 Pod ##在该节点上运行,该卷就会存在。正如卷的名字所述,它最初是空的。 - 实战使用共享卷的标准多容器POD、
#创建yaml文件cat >> emptyDir2.yaml << EOF apiVersion: v1 kind: Pod metadata: name: datagrand namespace: test spec: containers: - name: test1 image: nginx:1.7.9 volumeMounts: - name: log-storage mountPath: /usr/share/nginx/html - name: test2 image: centos volumeMounts: - name: log-storage mountPath: /html command: ["/bin/sh","-c"] args: - while true;do data >> /html/index.html; sleep 1; done volumes: - name: log-storage emptyDir: {} ##说明:在这个例子中,我们定义了一个名为HTML的卷。它的类型是emptyDir, ##这意味着当一个POD被分配到一个节点时,卷先被创建,并只要Pod在节点上 ##运行时,这个卷仍存在。正如名字所说,它最初是空的。第一容器运行nginx的 ##服务器并将共享卷挂载到目录/ usr /share/ nginx /html。第二容器使用centos ##的镜像,并将共享卷挂载到目录/HTML。每一秒,第二容器添加当前日期和时 ##间到index.html文件中,它位于共享卷。当用户发出一个HTTP请求到POD, ##nginx的服务器读取该文件并将其传递给响应请求的用户。#运行yaml kubectl create -f ./emptyDir2.yaml#查看Pod运行状态 kubectl get po -n test NAME READY STATUS RESTARTS AGE datagrand 2/2 Running 0 22m#进入容器test1 kubectl exec -it datagrand -c test1 /bin/bash -n test root@datagrand:/# cd /usr/share/nginx/html root@datagrand:/usr/share/nginx/html# ls index.html ##添加内容 root@datagrand:/usr/share/nginx/html# echo "this is a test" >> index.html#进入容器test2 kubectl exec -it datagrand -c test2 /bin/bash -n test [root@datagrand /]# cd html [root@datagrand html]# ls index.html [root@datagrand html]# cat index.html this is a test ##emptyDir卷是两个容器(test1和test2)共享的 - 参考文档
https://www.kubernetes.org.cn/2767.html
评论(0)