分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

Kubernetes部分Volume类型介绍及yaml示例--emptyDir

发布时间:2023-09-06 01:58责任编辑:顾先生关键词:暂无标签
Kubernetes部分Volume类型介绍及yaml示例--emptyDir(本地数据卷)

  1. 说明
    EmptyDir类型的volume创建于pod被调度到某个宿主机上的时候,而同一个pod内的容器都能读写EmptyDir中的同一个文件。一旦这个pod离开了这个宿主机,EmptyDir中的数据就会被永久删除。所以目前EmptyDir类型的volume主要用作临时空间,比如Web服务器写日志或者tmp文件需要的临时目录。
  2. 实战使用共享卷的标准单容器POD
    #创建yaml文件cat >> emptyDir.yaml << EOFapiVersion: v1kind: Podmetadata: ???labels: ???????name: test-emptypath ???????role: master ???name: test-emptypath ???namespace: testspec: ???containers: ???????- name: test-emptypath ???????????image: nginx:1.7.9 ???????????volumeMounts: ????????????- name: log-storage ????????????????mountPath: /tmp/ ???volumes: ???- name: log-storage ???????emptyDir: {}
    #启动emptyDir.yamlkubectl create -f ./emptyDir.yaml
    #查看Pod运行状态kubectl get po -n testNAME ????????????????????????READY ????STATUS ???RESTARTS ??AGEtest-emptypath ??????????????1/1 ??????Running ??0 ?????????3h##说明:当 Pod 被分配给节点时,首先创建 emptyDir 卷,并且只要该 Pod##在该节点上运行,该卷就会存在。正如卷的名字所述,它最初是空的。
  3. 实战使用共享卷的标准多容器POD、
    #创建yaml文件
    cat ?>> emptyDir2.yaml << EOFapiVersion: v1kind: Podmetadata: ???name: datagrand ???namespace: testspec: ???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; ???????????????donevolumes: ???- name: log-storage ???????emptyDir: {}##说明:在这个例子中,我们定义了一个名为HTML的卷。它的类型是emptyDir,##这意味着当一个POD被分配到一个节点时,卷先被创建,并只要Pod在节点上##运行时,这个卷仍存在。正如名字所说,它最初是空的。第一容器运行nginx的##服务器并将共享卷挂载到目录/ usr /share/ nginx /html。第二容器使用centos##的镜像,并将共享卷挂载到目录/HTML。每一秒,第二容器添加当前日期和时##间到index.html文件中,它位于共享卷。当用户发出一个HTTP请求到POD,##nginx的服务器读取该文件并将其传递给响应请求的用户。
    #运行yamlkubectl create -f ./emptyDir2.yaml 
    #查看Pod运行状态kubectl get po -n testNAME ????????????????????????READY ????STATUS ???RESTARTS ??AGEdatagrand ???????????????????2/2 ??????Running ??0 ?????????22m
    #进入容器test1kubectl exec -it datagrand -c test1 /bin/bash -n testroot@datagrand:/# cd /usr/share/nginx/htmlroot@datagrand:/usr/share/nginx/html# lsindex.html##添加内容root@datagrand:/usr/share/nginx/html# echo "this is a test" >> index.html 
    #进入容器test2kubectl exec -it datagrand -c test2 /bin/bash -n test[root@datagrand /]# cd html[root@datagrand html]# lsindex.html[root@datagrand html]# cat index.html this is a test##emptyDir卷是两个容器(test1和test2)共享的
  4. 参考文档
    https://www.kubernetes.org.cn/2767.html

Kubernetes部分Volume类型介绍及yaml示例--emptyDir

原文地址:http://blog.51cto.com/wutengfei/2125069

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved