kubernetes本地磁盘存储插件csi-driver-host-path使用(二)

  • Post author:
  • Post category:其他


1.创建sc:

# cat csi-storageclass.yaml 
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: csi-hostpath-sc
provisioner: hostpath.csi.k8s.io
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowVolumeExpansion: true

# kubectl apply -f csi-storageclass.yaml

# kubectl  get sc

NAME              PROVISIONER           RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE

csi-hostpath-sc   hostpath.csi.k8s.io   Delete          Immediate           true                   3d6h

2.创建pvc:

# cat csi-pvc.yaml 
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: csi-pvc2-vms3
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 15Gi
  storageClassName: csi-hostpath-sc # defined in csi-storageclass.yaml

# cat csi-pvc-block.yaml 
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc-cen7.9-vms
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: csi-hostpath-sc
  volumeMode: Block
  resources:
    requests:
      storage: 100Gi

# kubectl apply -f csi-pvc.yaml

# kubectl  get pvc

csi-pvc2-vms3                                            Bound    pvc-9f4863ed-8d9a-4329-bc42-4f693ab15210   15Gi       RWO            csi-hostpath-sc   2d1h

# kubectl apply -f csi-pvc-block.yaml

# kubectl  get pvc

pvc-cen7.9-vms                                           Bound    pvc-d7943ef1-ef30-47ae-b8dc-b0116c480dcf   100Gi      RWO            csi-hostpath-sc   3s

3.pvc克隆:

# cat csi-clone.yaml 
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: hp-pvc-clone
spec:
  storageClassName: csi-hostpath-sc
  dataSource:
    name: src-hp-pvc
    kind: PersistentVolumeClaim
    apiGroup: ""
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

# kubectl apply -f csi-clone.yaml

hp-pvc-clone                                             Bound    pvc-1f047bbc-62fb-4d57-ae04-3d2980b14421   1Gi        RWO            csi-hostpath-sc   14s

4.pvc快照:

# cat csi-snapshot.yaml 
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
  name: new-snapshot-demo
spec:
  volumeSnapshotClassName: csi-hostpath-snapclass
  source:
    persistentVolumeClaimName: csi-pvc

# kubectl  get volumesnapshot

NAME                                                               READYTOUSE   SOURCEPVC       SOURCESNAPSHOTCONTENT   RESTORESIZE   SNAPSHOTCLASS            SNAPSHOTCONTENT                                    CREATIONTIME   AGE

new-snapshot-demo                                                  true         csi-pvc                                 1Gi           csi-hostpath-snapclass   snapcontent-66756044-09e5-46c6-8963-7fad0e195ecd   3d4h           3d4h

# cat csi-restore.yaml 
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: hpvc-restore
spec:
  storageClassName: csi-hostpath-sc
  dataSource:
    name: new-snapshot-demo
    kind: VolumeSnapshot
    apiGroup: snapshot.storage.k8s.io
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

# kubectl apply -f csi-restore.yaml

# kubectl  get pvc

hpvc-restore                                             Bound    pvc-25330a01-16fb-4e97-943b-f81850473c98   1Gi        RWO            csi-hostpath-sc   3d4h

kubevirt交流群:766168407



版权声明:本文为BY_xiaopeng原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。