为 Ceph RGW 创建 BucketClass

Ceph Object Storage 可以通过 Container Object Storage Interface (COSI) 暴露给 Kubernetes 工作负载,为大数据分析、备份与恢复以及机器学习场景提供对象存储。在用户可以预配 bucket 之前,需要先创建 BucketClass

BucketClass 是一种模板资源,用于指定存储 driver、认证 secret 以及删除策略,这些配置将应用于基于该 BucketClass 创建的每个 bucket。

先决条件

要求说明
已运行且启用 RGW (S3) 的 Ceph 集群可以是内部(由 Rook 管理)或外部集群。
COSI 插件必须同时安装 COSI COSI for Ceph
包含 Ceph RGW 凭证的 Kubernetes Secret在下面的 步骤 3 中准备。

步骤 1 – 准备 Ceph 集群

从以下选项中选择 一个

选项说明
内部 Ceph由 Rook Operator 在平台 内部 部署和管理的 Ceph 集群。详细信息请参见 创建存储服务
外部 Ceph可从平台网络访问的独立 Ceph 集群。

步骤 2 – 安装 COSI 插件

安装以下集群插件:

  1. COSI
  2. COSI for Ceph

有关确切命令,请参见 安装

步骤 3 – 准备凭证 Secret

COSI 会从 Kubernetes Secret 中检索 RGW 凭证。请根据您的 Ceph 部署方式选择 一种 方法。

方法 A – 自动生成(Rook 管理的 Ceph)

  1. rook-ceph 命名空间中创建一个 CephObjectStoreUser

    # ceph-object-store-user.yaml
    apiVersion: ceph.rook.io/v1
    kind: CephObjectStoreUser
    metadata:
      name: user-for-cosi
      namespace: rook-ceph
    spec:
      store: object-store               # name of your CephObjectStore
      capabilities:
        bucket: ["read", "write"]
        user:   ["read", "write"]
  2. 应用该清单:

    kubectl apply -f ceph-object-store-user.yaml
  3. 获取自动生成的 Secret 名称(后续会用到):

    kubectl get cephobjectstoreuser user-for-cosi -n rook-ceph \
      -o jsonpath='{.status.info.secretName}'

方法 B – 手动(外部 Ceph)

  1. 获取 AccessKeySecretKeyRGW Endpoint

  2. 在目标项目/命名空间中创建一个 Secret,并为其添加标签,以便 UI 可以发现它:

    kubectl create secret generic ceph-external-creds -n <YOUR_NAMESPACE> \
      --from-literal=AccessKey=<YOUR_ACCESS_KEY> \
      --from-literal=SecretKey=<YOUR_SECRET_KEY> \
      --from-literal=Endpoint=http://<YOUR_RGW_ENDPOINT>
    
    kubectl label secret ceph-external-creds -n <YOUR_NAMESPACE> app=rook-ceph-rgw

    重要: 标签 app=rook-ceph-rgw 是平台 UI 列出该 Secret 的必需条件。

步骤 4 – 创建 BucketClass

选项 1 – UI 流程

  1. 导航到 Storage → Object StorageClass,然后单击 Create Object StorageClass

  2. 选择 Ceph Object Storage 作为 driver。

  3. 配置以下字段:

    • Deletion Policy – 当其 BucketClaim 被删除时,如何处理底层 bucket(默认值:Delete)。
    • Secret – 选择在 步骤 3 中准备的 Secret(仅显示带有 app=rook-ceph-rgw 标签的 Secret)。
    • Allocate Projects(可选) 限制仅供特定项目使用。
  4. 单击 Create

选项 2 – YAML(适合 GitOps)

使用正确的 Secret 引用创建 ceph-bucketclass.yaml

apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketClass
metadata:
  name: ceph-cosi-driver
  labels:
    project.cpaas.io/ALL_ALL: "true"
driverName: ceph.objectstorage.k8s.io
deletionPolicy: Delete
parameters:
  objectStoreUserSecretName: <your-secret-name>
  objectStoreUserSecretNamespace: <your-secret-namespace>

应用该清单:

kubectl apply -f ceph-bucketclass.yaml

验证与后续步骤

验证 BucketClass:

kubectl get bucketclass

当 BucketClass 准备就绪后,您可以创建引用它的 BucketBucketClaim 资源,从而为您的应用程序预配兼容 S3 的对象存储。