k8s volume

volume是k8s数据卷,常见的数据卷有4种类型,即EmptyDir,HostDir,NFS,Secret

EmptyDir

EmptyDir是一个空目录,他的生命周期和所属的 Pod 是完全一致的,
可能读者会奇怪,那还要他做什么?EmptyDir的用处是,可以在同一 Pod 内的不同容器之间共享工作过程中产生的文件。
一旦这个pod离开了这个宿主机,EmptyDirr中的数据就会被永久删除


[root@k8s-master demon2]# cat test-emptypath.yaml 
apiVersion: v1
kind: Pod
metadata:
  labels:
    name: test-emptypath
    role: master
  name: test-emptypath
spec:
  containers:
    - name: test-emptypath
      image: registry:5000/back_demon:1.0
      volumeMounts:
       - name: log-storage
         mountPath: /home/laizy/test/
      command:
      - /run.sh
  volumes:
  - name: log-storage
    emptyDir: {}

HostDir

HostDir属性的volume使得对应的容器能够访问当前宿主机上的指定目录。
[root@k8s-master demon2]# cat test-hostpath.yaml 
apiVersion: v1
kind: Pod
metadata:
  labels:
    name: test-hostpath
    role: master
  name: test-hostpath
spec:
  containers:
    - name: test-hostpath
      image: registry:5000/back_demon:1.0
      volumeMounts:
       - name: ssl-certs
         mountPath: /home/laizy/test/cert
         readOnly: true
      command:
      - /run.sh
  volumes:
  - name: ssl-certs
    hostPath:
     path: /etc/ssl/certs


NFS

支持网络存储
[root@k8s-master demon2]# cat test-nfspath.yaml 
apiVersion: v1
kind: Pod
metadata:
  labels:
    name: test-nfspath
    role: master
  name: test-nfspath
spec:
  containers:
    - name: test-nfspath
      image: registry:5000/back_demon:1.0
      volumeMounts:
       - name: nfs-storage
         mountPath: /home/laizy/test/
      command:
      - /run.sh
  volumes:
  - name: nfs-storage
    nfs:
     server: 192.168.20.47
     path: "/data/disk1"

Secret

Secret:Kubemetes提供了Secret来处理敏感数据


[root@k8s-master demon2]# cat secret.yaml 
apiVersion: v1
kind: Secret
metadata:
 name: mysecret
type: Opaque
data:
 username: emhlbnl1
 password: eWFvZGlkaWFv
[root@k8s-master demon2]# cat test-secret.yaml 
apiVersion: v1
kind: Pod
metadata:
  labels:
    name: test-secret
    role: master
  name: test-secret
spec:
  containers:
    - name: test-secret
      image: registry:5000/back_demon:1.0
      volumeMounts:
       - name: secret
         mountPath: /home/laizy/secret
         readOnly: true
      command:
      - /run.sh
  volumes:
  - name: secret
    secret:
     secretName: mysecret

关于Secret 在我另外一篇有详细说明
//www.greatytc.com/p/3bf692ee092e

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • feisky云计算、虚拟化与Linux技术笔记posts - 1014, comments - 298, trac...
    不排版阅读 3,957评论 0 5
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,890评论 25 709
  • 一、 K8s 是什么? Kubernetes(k8s)是自动化容器操作的开源平台,这些操作包括部署,调度和节点集群...
    loveroot阅读 6,670评论 1 21
  • •王越:VMware存储API整理,比如核心的存储池与卷两者的CURD。可以参考:VMware in OpenSt...
    笨手笨脚越阅读 5,737评论 0 2
  • 古老的希腊给予我无尽的幻想,那里是人类文明的起源,亚里士多德,苏格拉底,柏拉图,雅典城邦,都为希腊添上了浓厚的色彩...
    公主喵阅读 762评论 0 1