千家信息网

k8s 笔记 Pv、PVC 存储

发表于:2024-10-04 作者:千家信息网编辑
千家信息网最后更新 2024年10月04日,一、什么是 pv 和pvc1、 PersistentVolume(PV)是集群中已由管理员配置的一段网络存储。 集群中的资源就像一个节点是一个集群资源。 PV是诸如卷之类的卷插件,但是具有独立于使用P
千家信息网最后更新 2024年10月04日k8s 笔记 Pv、PVC 存储


一、什么是 pv 和pvc

1、 PersistentVolume(PV)是集群中已由管理员配置的一段网络存储。 集群中的资源就像一个节点是一个集群资源。 PV是诸如卷之类的卷插件,但是具有独立于使用PV的任何单个pod的生命周期。 该API对象捕获存储的实现细节,即NFS,iSCSI或云提供商特定的存储系统。


PV 支持的类型

常用的 类型有

GCEPersistentDisk

AWSElasticBlockStore

AzureFile

AzureDisk

FC (Fibre Channel)

FlexVolume

Flocker

NFS

iSCSI

RBD (Ceph Block Device)

CephFS

Cinder (OpenStack block storage)

Glusterfs

VsphereVolume

Quobyte Volumes

HostPath

VMware Photon

Portworx Volumes

ScaleIO Volumes


2、pv 的访问模式


ReadWriteOnce:单个节点读写


ReadOnlyMany:多节点只读


ReadWriteMany:多节点读写。挂载时只能使用一种模式。


3、pv 的回收模式


Retain - 需要管理员手工回收。

Recycle - 清除 PV 中的数据,效果相当于执行 rm -rf /thevolume/*。

Delete - 删除


创建 pv , 已nfs 存储为例


1、安装 nfs 服务器


2、创建存储路径


3、访问目录授权


mkdir -p /data/test/v1


echo "/data/test/v1 *(rw,sync,no_root_squash)" >> /etc/exports


exportfs -avr


编写yaml 文件

apiVersion: v1kind: PersistentVolumemetadata:  name: test01-pvspec:  capacity:     storage: 1Gi  accessModes:       - ReadWriteMany  storageClassName: test01-pv  persistentVolumeReclaimPolicy: Recycle  nfs:    path: /data/test/v1    server: 192.168.222.247


kubectl create -f test01_pv.yaml



pvc 的绑定

apiVersion: v1kind: PersistentVolumeClaimmetadata:   name: test01-pvc   namespace: test01spec:  storageClassName: test01-pv  accessModes:    - ReadWriteMany  resources:    requests:      storage: 1Gi---apiVersion: v1kind: Podmetadata:  name: myapp  namespace: test01spec:  containers:  - name: myapp    image: ikubernetes/myapp:v1    volumeMounts:    - name: html      mountPath: /usr/share/nginx/html  volumes:  - name: html    persistentVolumeClaim:      claimName: test01-pvc


kubectl create -f test01_pod_pvc.yaml


查看 pvc 和pod



绑定状态的pv 无法直接删除




0