文章大纲
ODF 部署完成后,会自动创建 ocs-storagecluster-ceph-rbd
存储类,用于提供应用所需的块存储。
块存储
如果应用的工作负载需要访问速度和密集型 IO ,使用块存储是个非常理想的选择。
使用块存储的应用用例:
- 数据库
- VM
配置 PVC
查看 ocs-storagecluster-ceph-rbd
的详细信息:
oc describe sc ocs-storagecluster-ceph-rbd
Name: ocs-storagecluster-ceph-rbd
IsDefaultClass: No
Annotations: description=Provides RWO Filesystem volumes, and RWO and RWX Block volumes
Provisioner: openshift-storage.rbd.csi.ceph.com
Parameters: clusterID=openshift-storage,csi.storage.k8s.io/controller-expand-secret-name=rook-csi-rbd-provisioner,csi.storage.k8s.io/controller-expand-secret-namespace=openshift-storage,csi.storage.k8s.io/fstype=ext4,csi.storage.k8s.io/node-stage-secret-name=rook-csi-rbd-node,csi.storage.k8s.io/node-stage-secret-namespace=openshift-storage,csi.storage.k8s.io/provisioner-secret-name=rook-csi-rbd-provisioner,csi.storage.k8s.io/provisioner-secret-namespace=openshift-storage,imageFeatures=layering,imageFormat=2,pool=ocs-storagecluster-cephblockpool
AllowVolumeExpansion: True
MountOptions: <none>
ReclaimPolicy: Delete
VolumeBindingMode: Immediate
Events: <none>
由上面的输出可以看到存储类的调配用的是 openshift-storage.rbd.csi.ceph.com
使用的的存储池是 ocs-storagecluster-cephblockpool
后续可以自定义存储类使用自定义的池。
创建 PVC 与文件存储的类似:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: app-rbd
spec:
accessModes:
- ReadWriteOnce
storageClassName: ocs-storagecluster-ceph-rbd
resources:
requests:
storage: 1Gi
需要注意的是 accessModes 应该是 ReadWriteOnce
。
oc apply -f app-rbd.yaml
persistentvolumeclaim/app-rbd created
oc get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
app-rbd Bound pvc-5acf855f-50ba-418e-bd23-0ac3b72236f5 1Gi RWO ocs-storagecluster-ceph-rbd 15s
创建示例应用来使用对应的 PVC:
Volumes:
mariadb-data:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: app-rbd
ReadOnly: false
应用中查看映射过来的 rbd 块设备:
oc rsh mariadb-2-m9znf
sh-4.4$ df -h /var/lib/mysql/data/
Filesystem Size Used Avail Use% Mounted on
/dev/rbd0 976M 180M 781M 19% /var/lib/mysql/data