ODF 集群部署好后,接下来就是使用 ODF 提供的存储了,ODF 基于存储类的为应用动态的调配 PV 提供存储。
ODF 部署完成后,默认会创键以下存储类:
1 2 3 4 5 6 oc get sc -o name storageclass.storage.k8s.io/imxcai-lvmset storageclass.storage.k8s.io/ocs-storagecluster-ceph-rbd storageclass.storage.k8s.io/ocs-storagecluster-ceph-rgw storageclass.storage.k8s.io/ocs-storagecluster-cephfs storageclass.storage.k8s.io/openshift-storage.noobaa.io
ODF 默认提供的存储类 不同的存储类用于支持不同的存储需求:
ocs-storagecluster-ceph-rbd:由 Rook-Ceph Operator 安装,提供块存储设备。
ocs-storagecluster-cephfs:由 Rook-Ceph Operator 安装,提供共享和分布式的文件系统。
ocs-storagecluster-ceph-rgw:由 Rook-Ceph Operator 安装,提供本地对象存储。
openshift-storage.noobaa.io:由 NooBaa Operator 安装,提供多云对象网关服务。
文件存储 文件系统存储是最常见的存储类型,它拥有文件系统层次结构,在诸多应用程序中使用的非常普遍,例如:
配置 PVC 通过 oc describe sc ocs-storagecluster-cephfs 可以查看存储类的详细信息:
1 2 3 4 5 6 7 8 9 10 11 oc describe sc ocs-storagecluster-cephfs Name: ocs-storagecluster-cephfs IsDefaultClass: No Annotations: description=Provides RWO and RWX Filesystem volumes Provisioner: openshift-storage.cephfs.csi.ceph.com Parameters: clusterID=openshift-storage,csi.storage.k8s.io/controller-expand-secret-name=rook-csi-cephfs-provisioner,csi.storage.k8s.io/controller-expand-secret-namespace=openshift-storage,csi.storage.k8s.io/node-stage-secret-name=rook-csi-cephfs-node,csi.storage.k8s.io/node-stage-secret-namespace=openshift-storage,csi.storage.k8s.io/provisioner-secret-name=rook-csi-cephfs-provisioner,csi.storage.k8s.io/provisioner-secret-namespace=openshift-storage,fsName=ocs-storagecluster-cephfilesystem AllowVolumeExpansion: True MountOptions: <none> ReclaimPolicy: Delete VolumeBindingMode: Immediate Events: <none>
可以知道使用的调配器是 openshift-storage.cephfs.csi.ceph.com 。 Parameters 指定了使用调配器用的参数:
1 2 3 4 5 6 7 8 clusterID=openshift-storage csi.storage.k8s.io/controller-expand-secret-name=rook-csi-cephfs-provisioner csi.storage.k8s.io/controller-expand-secret-namespace=openshift-storage csi.storage.k8s.io/node-stage-secret-name=rook-csi-cephfs-node csi.storage.k8s.io/node-stage-secret-namespace=openshift-storage csi.storage.k8s.io/provisioner-secret-name=rook-csi-cephfs-provisioner csi.storage.k8s.io/provisioner-secret-namespace=openshift-storage fsName=ocs-storagecluster-cephfilesystem
从上述可知使用的 Ceph 集群的名字,使用的凭据来自于哪些项目中的 secret,以及后端使用的 Ceph 文件系统是 ocs-storagecluster-cephfilesystem ,这个也可以在 Ceph 集群中进行验证:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 oc exec -it -n openshift-storage rook-ceph-operator-7df548cc9-gb8tr -- /bin/bash bash-4.4$ ceph -c /var/lib/rook/openshift-storage/openshift-storage.config fs status ocs-storagecluster-cephfilesystem - 0 clients ================================= +------+----------------+-------------------------------------+---------------+-------+-------+ | Rank | State | MDS | Activity | dns | inos | +------+----------------+-------------------------------------+---------------+-------+-------+ | 0 | active | ocs-storagecluster-cephfilesystem-b | Reqs: 0 /s | 10 | 13 | | 0-s | standby-replay | ocs-storagecluster-cephfilesystem-a | Evts: 0 /s | 0 | 3 | +------+----------------+-------------------------------------+---------------+-------+-------+ +--------------------------------------------+----------+-------+-------+ | Pool | type | used | avail | +--------------------------------------------+----------+-------+-------+ | ocs-storagecluster-cephfilesystem-metadata | metadata | 1536k | 847G | | ocs-storagecluster-cephfilesystem-data0 | data | 0 | 847G | +--------------------------------------------+----------+-------+-------+ +-------------+ | Standby MDS | +-------------+ +-------------+ MDS version: ceph version 14.2.11-208.el8cp (6738ba96f296a41c24357c12e8d594fbde457abc) nautilus (stable)
创建一个名为 app-cephfs 的 pvc 示例:
1 2 3 4 5 6 7 8 9 10 11 apiVersion: v1 kind: PersistentVolumeClaim metadata: name: app-cephfs spec: accessModes: - ReadWriteMany storageClassName: ocs-storagecluster-cephfs resources: requests: storage: 1Gi
应用 pvc 的资源定义文件,并查看创建的资源,可以看到有跟存储类提供的 pv 进行了 Bound:
1 2 3 4 5 oc apply -f cephfs-pvc.yaml persistentvolumeclaim/app-cephfs created [student@workstation ~]$ oc get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE app-cephfs Bound pvc-78f73a09-7f3d-4eba-963e-9b890151a657 1Gi RWX ocs-storagecluster-cephfs 3s
创建示例应用来使用该 PVC 资源,在 Deployment 中指定 volume 相关信息:
在 Pod 中可以看到挂载的信息:
1 2 3 4 oc rsh nginx-sample-5bc467cd75-bn5cs sh-4.2$ df -h /opt/app-root/src/ Filesystem Size Used Avail Use% Mounted on 172.30.123.14:6789,172.30.6.192:6789,172.30.199.54:6789:/volumes/csi/csi-vol-502f03f3-c58b-11ee-928f-0a580a090205/22996a45-ae8a-424d-9c71-b5c2dd7e3073 1.0G 0 1.0G 0% /opt/app-root/src
评论· · · · · ·