一、PV/PVC-简介

PersistentVolume(PV):是集群中已经由kubernetes管理员配置的一个网络存储,集群中的存储资源一个集群资源,即不隶属于任何namespace,PV的数据最终存储在硬件存储,pod不能直接挂载PV,PV需要绑定给PVC并最终由pod挂载PVC使用, PV其支持NFS、Ceph、商业存储或云提供商的特定的存储等, 可以自定义PV的类型是块还是文件存储、存储空间大小、 访问模式等,PV的生命周期独立于Pod, 即当使用PV的Pod被删除时可以对PV中的数据没有影响。

PersistentVolumeClaim(PVC):是pod对存储的请求, pod挂载PVC并将数据存储在PVC,而PVC需要绑定到PV才能使用,另外PVC在创建的时候要指定namespace, 即pod要和PVC运行在同一个namespace, 可以对PVC设置特定的空间大小和访问模式, 使用PVC的pod在删除时也可以对PVC中的数据没有影响。

PVC

  • 用于实现pod和storage的解耦, 这样我们修改storage的时候不需要修改pod。
  • 与NFS的区别, 可以在PV和PVC层面实现实现对存储服务器的空间分配、 存储的访问权限管理等。
  • kubernetes 从1.0版本开始支持PersistentVolume和PersistentVolumeClaim。

官方不同存储卷支持的访问模式:https://kubernetes.io/docs/concepts/storage/persistent-volumes/

PV是对底层网络存储的抽象, 即将网络存储定义为一种存储资源, 将一个整体的存储资源拆分成多份后给不同的业务使用。
PVC是对PV资源的申请调用, pod是通过PVC将数据保存至PV, PV再把数据保存至真正的硬件存储。

二、PersistentVolume参数

root@easzlab-deploy:~# kubectl explain PersistentVolume
KIND:     PersistentVolume
VERSION:  v1

DESCRIPTION:
     PersistentVolume (PV) is a storage resource provisioned by an
     administrator. It is analogous to a node. More info:
     https://kubernetes.io/docs/concepts/storage/persistent-volumes

FIELDS:
   apiVersion    <string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources

   kind    <string>
     Kind is a string value representing the REST resource this object
     represents. Servers may infer this from the endpoint the client submits
     requests to. Cannot be updated. In CamelCase. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

   metadata    <Object>
     Standard object's metadata. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata

   spec    <Object>
     spec defines a specification of a persistent volume owned by the cluster.
     Provisioned by an administrator. More info:
     https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistent-volumes

   status    <Object>
     status represents the current information/status for the persistent volume.
     Populated by the system. Read-only. More info:
     https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistent-volumes

root@easzlab-deploy:~# 

Capacity: #当前PV空间大小

root@easzlab-deploy:~# kubectl explain PersistentVolume.spec.capacity
KIND:     PersistentVolume
VERSION:  v1

FIELD:    capacity <map[string]string>

DESCRIPTION:
     capacity is the description of the persistent volume's resources and
     capacity. More info:
     https://kubernetes.io/docs/concepts/storage/persistent-volumes#capacity

     Quantity is a fixed-point representation of a number. It provides
     convenient marshaling/unmarshaling in JSON and YAML, in addition to
     String() and AsInt64() accessors.

     The serialization format is:

     <quantity> ::= <signedNumber><suffix> (Note that <suffix> may be empty,
     from the "" case in <decimalSI>.) <digit> ::= 0 | 1 | ... | 9 <digits> ::=
     <digit> | <digit><digits> <number> ::= <digits> | <digits>.<digits> |
     <digits>. | .<digits> <sign> ::= "+" | "-" <signedNumber> ::= <number> |
     <sign><number> <suffix> ::= <binarySI> | <decimalExponent> | <decimalSI>
     <binarySI> ::= Ki | Mi | Gi | Ti | Pi | Ei (International System of units;
     See: http://physics.nist.gov/cuu/Units/binary.html) <decimalSI> ::= m | ""
     | k | M | G | T | P | E (Note that 1024 = 1Ki but 1000 = 1k; I didn't
     choose the capitalization.) <decimalExponent> ::= "e" <signedNumber> | "E"
     <signedNumber>

     No matter which of the three exponent forms is used, no quantity may
     represent a number greater than 2^63-1 in magnitude, nor may it have more
     than 3 decimal places. Numbers larger or more precise will be capped or
     rounded up. (E.g.: 0.1m will rounded up to 1m.) This may be extended in the
     future if we require larger or smaller quantities.

     When a Quantity is parsed from a string, it will remember the type of
     suffix it had, and will use the same type again when it is serialized.

     Before serializing, Quantity will be put in "canonical form". This means
     that Exponent/suffix will be adjusted up or down (with a corresponding
     increase or decrease in Mantissa) such that:
     a. No precision is lost b. No fractional digits will be emitted c. The
     exponent (or suffix) is as large as possible. The sign will be omitted
     unless the number is negative.

     Examples:
     1.5 will be serialized as "1500m" 1.5Gi will be serialized as "1536Mi"

     Note that the quantity will NEVER be internally represented by a floating
     point number. That is the whole point of this exercise.

     Non-canonical values will still parse as long as they are well formed, but
     will be re-emitted in their canonical form. (So always use canonical form,
     or don't diff.)

     This format is intended to make it difficult to use these numbers without
     writing some sort of special handling code in the hopes that that will
     cause implementors to also use a fixed point implementation.
root@easzlab-deploy:~# 

accessModes : 访问模式

root@easzlab-deploy:~# kubectl explain PersistentVolume.spec.accessModes
KIND:     PersistentVolume
VERSION:  v1

FIELD:    accessModes <[]string>

DESCRIPTION:
     accessModes contains all ways the volume can be mounted. More info:
     https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes
root@easzlab-deploy:~# 

访问模式有:
ReadWriteOnce(RWO)

  • 该卷可以由单个节点以读写方式安装。ReadWriteOnce 访问模式仍然可以允许多个 pod 在同一节点上运行时访问卷。

ReadOnlyMany(ROX)

  • 该卷可以被许多节点以只读方式安装。

ReadWriteMany(RWX)

  • 该卷可以被许多节点以读写方式安装。

ReadWriteOncePod

  • 该卷可以由单个 Pod 以读写方式挂载。如果要确保整个集群中只有一个 pod 可以读取或写入 PVC,请使用 ReadWriteOncePod 访问模式。这仅支持 CSI 卷和 Kubernetes 1.22+ 版本。

persistentVolumeReclaimPolicy #删除机制即删除存储卷卷时候, 已经创建好的存储卷由以下删除操作

root@easzlab-deploy:~# kubectl explain PersistentVolume.spec.persistentVolumeReclaimPolicy
KIND:     PersistentVolume
VERSION:  v1

FIELD:    persistentVolumeReclaimPolicy <string>

DESCRIPTION:
     persistentVolumeReclaimPolicy defines what happens to a persistent volume
     when released from its claim. Valid options are Retain (default for
     manually created PersistentVolumes), Delete (default for dynamically
     provisioned PersistentVolumes), and Recycle (deprecated). Recycle must be
     supported by the volume plugin underlying this PersistentVolume. More info:
     https://kubernetes.io/docs/concepts/storage/persistent-volumes#reclaiming

     Possible enum values:
     - `"Delete"` means the volume will be deleted from Kubernetes on release
     from its claim. The volume plugin must support Deletion.
     - `"Recycle"` means the volume will be recycled back into the pool of
     unbound persistent volumes on release from its claim. The volume plugin
     must support Recycling.
     - `"Retain"` means the volume will be left in its current phase (Released)
     for manual reclamation by the administrator. The default policy is Retain.
root@easzlab-deploy:~# 

Retain – 删除PV后保持原装, 最后需要管理员手动删除
Recycle – 空间回收, 及删除存储卷上的所有数据(包括目录和隐藏文件),目前仅支持NFS和hostPath
Delete – 自动删除存储卷

volumeMode #卷类型

定义存储卷使用的文件系统是块设备还是文件系统, 默认为文件系统

root@easzlab-deploy:~# kubectl explain PersistentVolume.spec.volumeMode
KIND:     PersistentVolume
VERSION:  v1

FIELD:    volumeMode <string>

DESCRIPTION:
     volumeMode defines if a volume is intended to be used with a formatted
     filesystem or to remain in raw block state. Value of Filesystem is implied
     when not included in spec.
root@easzlab-deploy:~# 

mountOptions #附加的挂载选项列表, 实现更精细的权限控制ro #等

官方提供的基于各后端存储创建的PV支持的访问模式

https://kubernetes.io/zh-cn/docs/concepts/storage/persistent-volumes/

三、PersistentVolumeClaim创建参数

accessModes : PVC 访问模式,

  • ReadWriteOnce – PVC只能被单个节点以读写权限挂载, RWO
  • ReadOnlyMany – PVC以可以被多个节点挂载但是权限是只读的,ROX
  • ReadWriteMany – PVC可以被多个节点是读写方式挂载使用,RWX

resources: #定义PVC创建存储卷的空间大小
selector: #标签选择器, 选择要绑定的PV

  • matchLabels #匹配标签名称
  • matchExpressions #基于正则表达式匹配

volumeName #要绑定的PV名称
volumeMode #卷类型

  • 定义PVC使用的文件系统是块设备还是文件系统, 默认为文件系统

Volume-存储卷类型

static: 静态存储卷 ,需要在使用前手动创建PV、 然后创建PVC并绑定到PV,然后挂载至pod使用, 适用于PV和PVC相对比较固定的业务场景。
dynamin: 动态存储卷,先创建一个存储类storageclass, 后期pod在使用PVC的时候可以通过存储类动态创建PVC, 适用于有状态服务集群如MySQL一主多从、zookeeper集群等。

 

原文地址:http://www.cnblogs.com/cyh00001/p/16815782.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性