kubernetes学习 数据管理 Volume (二)

二、hostPath

  hostPath Volume 的作用是将 Docker Host 文件系统中已存在的目录 mountPod 的容器。

  大部分应用都不会使用 hostPath Volume, 因为这实际上增加了 Pod 与节点的耦合,限制了 Pod 的使用。

  不过那些需要访问 KubernetesDocker 内部数据的应用则需要使用 hostPath

  如果 Pod 被销毁了,hostPath 对应目录还是会被保留,从这一点来看,hostPath 的持久性比 emptyDir 强。

  不过一旦 H  ost 崩溃, hostPath 也就无法访问了。

三、外部 Storage Provider

  如果 Kubernetes 部署在诸如 AWS、GCE、Azure 等公有云上,可以直接使用云硬盘作为 Volume。

  一个 AWS Elastic Block Store 的例子:

apiVersion: v1
kind: Pod
metadata:
  name: using-ebs
spec:
  containers:
  - image: busybox
    name: using-ebs
    volumeMounts:
    - mountPath: /test-rbs
      name: ebs-volume
  volumes:
  - name: ebs-volume
    awsElasticBlockStore:
      volumeID: <volume-id>
      fsType: ext4

    要在 Pod 中使用 ESB volume,必须先在 AWS 中创建,然后通过 volume-id 引用。

  一个 Ceph 的例子:  

apiVersion: v1
kind: Pod
metadata:
  name: using-ceph
spec:
  containers:
  - image: busybox
    name: using-ceph
    volumeMounts:
    - mountPath: /test-ceph
      name: ceph-volume
  volumes:
  - name: ceph-volume
    cephfs:
        path:/some/path/in/side/cephfs
        monitors:"10.16.154.78:6789"
        secretFile: "/etc/ceph/admin.secret"

    Ceph 文件系统的 /some/path/in/side/cephfs 目录被 mount 到容器路径 /test-ceph。

  * 相对于 emptyDirhotPath,这些 Volume 类型的最大特点就是不依赖 KubernetesVolume 的底层基础设施由独立的存储系统管理,与 Kubernetes 集群是分离的。数据被持久化后,即使整个 Kubernetes 崩溃也不会受损。

  

原文地址:https://www.cnblogs.com/Lyh1997/p/10295142.html