首页 > 其他分享 >kubernetes---PV/PVC

kubernetes---PV/PVC

时间:2022-10-22 14:33:51浏览次数:57  
标签:will 存储 PV persistent --- PVC PersistentVolume

一、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集群等。

 

标签:will,存储,PV,persistent,---,PVC,PersistentVolume
From: https://www.cnblogs.com/cyh00001/p/16815782.html

相关文章

  • vue-router
    入门1.前言router路由应为vue是单页应用不会有那么多html让我们跳转所有要使用路由做页面的跳转Vue路由允许我们通过不同的URL访问不同的内容。通过Vue可以实......
  • 【10.15-10.21】博客精彩回顾
    一、优秀文章推荐1.​​SQL进阶篇之高级应用​​2.​​手写自定义springboot-starter,感受框架的魅力和原理​​3.​​【数据结构(c语言版)】树的概念以及结构​​4.​​驱动......
  • 01背包问题-简单1
    //0·1背包问题---采药.cpp---洛谷1048#include<iostream>#include<algorithm>#include<iomanip>usingnamespacestd;constintN=1e3+10;intTime[1001];......
  • InfluxDB Cluster - InfluxDB Enterprise 集群的开源替代方案
    InfluxDBCluster-InfluxDBEnterprise集群的开源替代方案InfluxDBCluster-一个开源分布式时间序列数据库,InfluxDBEnterprise的开源替代方案GitHub:chengshiwen/......
  • 淘宝账户系统的设计缺陷bug漏洞(死循环)2022-12
    朋友的一个账户几年没登录了,结果昨天登的时候登不上,在账号检测界面死循环在手机界面说要联系客服=>跳转联系页面=>联系之前需登录=>跳转登录界面,就是这样的无限死循......
  • HTML标签-表单标签-概述
    HTML标签-表单标签-概述HTML标签:表单标签表单:概念:用于采集用户输入的数据的。用于和服务器进行交互。from:用于定义表单的。可以定义一个范围,范围......
  • 基于Windows Server 2022系统-Exchange Server 2019基本安装
    1.准备一台WindowsServer2022系统,要首先安装以下软件:a..NETFramework4.8b.VisualC++RedistributablePackageforVisualStudio2012c.VisualC++Redistributab......
  • SpringCloud-01 Rest学习环境搭建笔记
    @​​TOC​​写在前面由于刚开始创建第一个项目的时候,出现了版本冲突问题,所以最后没有启动下来,但是我大部分的图片都是用的第一次的,所以大家可以主观的把图片中父项目Spring......
  • SpringCloud-03 Netflix Ribbon学习笔记
    @​​TOC​​一、Ribbon简介1、什么是Ribbon?SpringCloudRibbon是基于NetflixRibbon实现的一套客户端负载均衡的工具,它可以很好地控制HTTP和TCP客户端的行为。简单的......
  • java基础-->注释
    注释注释:注释起到对代码标注和解释的作用,如果你去看看JDK源码,会发现他们有许多的注释,而且注释是比代码还要多的,可见为代码添加注释是非常重要的,写好注释能让别人更加容易......