k8s 筆記 Pv、PVC 存儲


1、什麼是 pv 和pvc html

一、  PersistentVolume(PV)是集羣中已由管理員配置的一段網絡存儲。 集羣中的資源就像一個節點是一個集羣資源。 PV是諸如卷之類的卷插件,可是具備獨立於使用PV的任何單個pod的生命週期。 該API對象捕獲存儲的實現細節,即NFS,iSCSI或雲提供商特定的存儲系統。python


PV 支持的類型nginx

經常使用的 類型有api

GCEPersistentDisk 服務器

AWSElasticBlockStore 網絡

AzureFile app

AzureDisk ide

FC (Fibre Channel) spa

FlexVolume 插件

Flocker 

NFS 

iSCSI 

RBD (Ceph Block Device) 

CephFS 

Cinder (OpenStack block storage) 

Glusterfs 

VsphereVolume 

Quobyte Volumes 

HostPath

VMware Photon 

Portworx Volumes 

ScaleIO Volumes 


二、pv  的訪問模式  


ReadWriteOnce:單個節點讀寫


ReadOnlyMany:多節點只讀


ReadWriteMany:多節點讀寫。掛載時只能使用一種模式。


三、pv  的回收模式 


Retain – 須要管理員手工回收。

Recycle – 清除 PV 中的數據,效果至關於執行 rm -rf /thevolume/*。

Delete – 刪除 


建立 pv , 已nfs 存儲爲例


一、安裝 nfs 服務器


二、建立存儲路徑


三、訪問目錄受權 


mkdir -p /data/test/v1


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


exportfs -avr


編寫yaml 文件

apiVersion: v1
kind: PersistentVolume
metadata:
  name: test01-pv
spec:
  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


image.png


pvc 的綁定 

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
   name: test01-pvc
   namespace: test01
spec:
  storageClassName: test01-pv
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi

---
apiVersion: v1
kind: Pod
metadata:
  name: myapp
  namespace: test01
spec:
  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 



image.png

綁定狀態的pv 沒法直接刪除

相關文章
相關標籤/搜索