大家好,欢迎来到IT知识分享网。
1 Volumes含义
一个 volume 就是一个目录,可能包含一些数据,这些数据对pod中的所有容器都是可用的,这个目录怎么使用,什么类型,由什么组成都是由特殊的volume 类型决定的。
2 优点: 当很多容器在同一Pod中运行的时候,进行数据文件的共享。
Pod中容器数据持久化。
缺点 。
3 Volumes的类型
3.1 emptyDir
一个emptyDir 第一次创建是在一个pod被指定到具体node的时候,并且会一直存在在pod的生命周期当中,正如它的名字一样,它初始化是一个空的目录,pod中的容器都可以读写这个目录,这个目录可以被挂在到各个容器相同或者不相同的的路径下。当一个pod因为任何原因被移除的时候,这些数据会被永久删除。
3.2 hostPath
一个hostPath类型的磁盘就是挂在了主机的一个文件或者目录。HostDir属性的volume使得对应的容器能够访问当前宿主机上的指定目录。
3.3 NFS
支持网络存储。nfs使的我们可以挂在已经存在的共享的Pod中,和emptyDir不同的是,emptyDir会被删除当我们的Pod被删除的时候,但是nfs不会被删除,仅仅是解除挂在状态而已,这就意味着NFS能够允许我们提前对数据进行处理,而且这些数据可以在Pod之间相互传递.并且,nfs可以同时被多个pod挂在并进行读写。
3.4 Secret
一个Secrets磁盘是存储敏感信息的磁盘,例如密码之类。我们可以将secrets存储到api中,使用的时候以文件的形式挂载到pod中,而不用连接api,Secrets是通过tmpfs来支撑的,所有secrets永远不会存储到不稳定的地方。
4 yaml脚本创建Volumes
4.1 创建emptyDir 的yaml脚本。
cat test-emptypath.yaml apiVersion: v1 kind: Pod metadata: labels: name: test-emptypath role: master name: test-emptypath spec: containers: - name: test-emptypath image: tomcat volumeMounts: - name: log-storage mountPath: /usr/local/tomcat/logs command: - /run.sh volumes: - name: log-storage emptyDir: {}
4.2 创建hostPath 的yaml脚本。
cat test-hostpath.yaml apiVersion: v1 kind: Pod metadata: labels: name: test-hostpath role: master name: test-hostpath spec: containers: - name: test-hostpath image: tomcat volumeMounts: - name: certs mountPath: /usr/local/tomcat/logs readOnly: true command: - /run.sh volumes: - name: certs hostPath: path: /etc/ssl/certs
4.3 创建NFS 的yaml脚本。
cat test-nfspath.yaml apiVersion: v1 kind: Pod metadata: labels: name: test-nfspath role: master name: test-nfspath spec: containers: - name: test-nfspath image: tomcat volumeMounts: - name: nfs-storage mountPath: /usr/local/tomcat/logs command: - /run.sh volumes: - name: nfs-storage nfs: server: 192.168.0.1 path: "/data/logs"
4.4 创建Secret 的yaml脚本。
cat secret.yaml apiVersion: v1 kind: Secret metadata: name: mysecret type: Opaque data: username: emhlbnl1 password: eWFvZGlkaWFv cat test-secret.yaml apiVersion: v1 kind: Pod metadata: labels: name: test-secret role: master name: test-secret spec: containers: - name: test-secret image: tomcat volumeMounts: - name: secret mountPath: /home/secret readOnly: true command: - /run.sh volumes: - name: secret secret: secretName: mysecret
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/187976.html