存储卷与数据持久化(二)

[root@k8s-master01 yaml]# cat pv-nfs-demo.yaml 
apiVersion : v1
kind: PersistentVolume
metadata:
  name: pv-nfs-demo
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    path: "/data/redis002"
    server: 10.122.138.244
[root@k8s-master01 yaml]# kubectl apply -f pv-nfs-demo.yaml 
persistentvolume/pv-nfs-demo created
[root@k8s-master01 yaml]# kubectl describe pv-nfs-demo
error: the server doesn't have a resource type "pv-nfs-demo"
[root@k8s-master01 yaml]# kubectl describe pv/pv-nfs-demo
Name:            pv-nfs-demo
Labels:          <none>
Annotations:     <none>
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    
Status:          Available
Claim:           
Reclaim Policy:  Retain
Access Modes:    RWX
VolumeMode:      Filesystem
Capacity:        5Gi
Node Affinity:   <none>
Message:         
Source:
    Type:      NFS (an NFS mount that lasts the lifetime of a pod)
    Server:    10.122.138.244
    Path:      /data/redis002
    ReadOnly:  false
Events:        <none>

上面描述信息中的Available表明该PV 已经可以接收pvc的绑定请求,并且在绑定完成后转变成Bound

 

[root@k8s-master01 yaml]# cat pvc-demo-0001.yaml 
apiVersion : v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-demo-0001
  namespace: storage
spec:
  
  volumeMode: Filesystem
  accessModes: ["ReadWriteMany"]
  resources: 
    requests:
      storage: 3Gi
    limits:
      storage: 10Gi

 

[root@k8s-master01 yaml]# kubectl apply -f pvc-demo-0001.yaml 
persistentvolumeclaim/pvc-demo-0001 created

[root@k8s-master01 yaml]# kubectl get pvc pvc-demo-0001 -n storage
NAME            STATUS   VOLUME        CAPACITY   ACCESS MODES   STORAGECLASS   AGE
pvc-demo-0001   Bound    pv-nfs-demo   5Gi        RWX                           2m29s
[root@k8s-master01 yaml]# kubectl get pv/pv-nfs-demo -n storage
NAME          CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                   STORAGECLASS   REASON   AGE
pv-nfs-demo   5Gi        RWX            Retain           Bound    storage/pvc-demo-0001                           18m

上面结果显示,被pvc资源pvc-demo-0001绑定的pv资源pv-nfs-demo的状态也将从Available转变成Bound

 

存储类

 

posted @ 2021-08-19 18:14  拥抱大海,面向天空  阅读(22)  评论(0)    收藏  举报