k8s的pvc扩容(csi-rbd模式)


k8s下的pvc扩容(csi-rbd模式)

上一篇我们安装了csi-ceph-rbd的动态供给程序。本篇我们测下csi-rbd的pvc扩容

块设备

  • 修改sc,添加允许扩容的选项allowVolumeExpansion: true
# cat csi-rbd-sc.yaml 
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
   name: csi-rbd-sc
   namespace: ceph-csi
provisioner: rbd.csi.ceph.com
parameters:
   clusterID: 278f25a0-43d1-45f8-8ac1-fc228d8091f6
   pool: wh-k8s
   imageFeatures: layering
   csi.storage.k8s.io/provisioner-secret-name: csi-rbd-secret
   csi.storage.k8s.io/provisioner-secret-namespace: ceph-csi
   csi.storage.k8s.io/controller-expand-secret-name: csi-rbd-secret
   csi.storage.k8s.io/controller-expand-secret-namespace: ceph-csi
   csi.storage.k8s.io/node-stage-secret-name: csi-rbd-secret
   csi.storage.k8s.io/node-stage-secret-namespace: ceph-csi
   csi.storage.k8s.io/fstype: ext4
reclaimPolicy: Delete
allowVolumeExpansion: true
mountOptions:
   - discard
  • 创建pvc
# cat raw-block-pvc.yaml 
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: raw-block-pvc
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Block
  resources:
    requests:
      storage: 1Gi
  storageClassName: csi-rbd-sc
  • 创建pod
# cat raw-block-pod.yaml 
---
apiVersion: v1
kind: Pod
metadata:
  name: pod-with-raw-block-volume
spec:
  containers:
    - name: centos
      image: centos:latest
      command: ["/bin/sleep", "infinity"]
      volumeDevices:
        - name: data
          devicePath: /dev/xvdb
  volumes:
    - name: data
      persistentVolumeClaim:
        claimName: raw-block-pvc
  • 扩容,修改pvc
修改storage为2G
# cat raw-block-pvc.yaml 
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: raw-block-pvc
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Block
  resources:
    requests:
      storage: 1Gi
  storageClassName: csi-rbd-sc
#kubectl edit pvc raw-block-pvc
# kubectl  get pvc
NAME            STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
raw-block-pvc   Bound    pvc-58377379-4ecf-466e-a16f-9696278da103   2Gi        RWO            csi-rbd-sc     128m
  • 检查
[root@pod-with-raw-block-volume /]# fdisk -l /dev/xvdb
Disk /dev/xvdb: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 65536 bytes / 65536 bytes

另外,扩容的时候是无缝扩容的。无需停机。直接修改pvc拉伸卷