8.2. 使用命令行界面创建对象 Bucket 声明

在使用命令行界面创建对象 Bucket 声明时,您会获得一个配置映射和一个 Secret,其中包含应用使用对象存储服务所需的所有信息。

先决条件

  • 下载 MCG 命令行界面:

    # subscription-manager repos --enable=rh-ocs-4-for-rhel-8-x86_64-rpms
    # yum install mcg

流程

  1. 使用命令行界面生成新 bucket 和凭据的详细信息。运行以下命令:

    # noobaa obc create <obc-name> -n openshift-storage

    <obc-name> 替换为一个唯一的对象 Bucket Claim 名称,例如 myappobc

    另外,您可以使用 --app-namespace 选项指定创建 Object Bucket Claim 配置映射和 secret 的命名空间,如 myapp-namespace

    输出示例:

    INFO[0001] ✅ Created: ObjectBucketClaim "test21obc"

    MCG 命令行界面已创建了必要的配置,并已向 OpenShift 告知新的 OBC。

  2. 运行以下命令来查看对象 Bucket 声明:

    # oc get obc -n openshift-storage

    输出示例:

    NAME        STORAGE-CLASS                 PHASE   AGE
    test21obc   openshift-storage.noobaa.io   Bound   38s
  3. 运行以下命令,以查看新对象 Bucket 声明的 YAML 文件:

    # oc get obc test21obc -o yaml -n openshift-storage

    输出示例:

    apiVersion: objectbucket.io/v1alpha1
    kind: ObjectBucketClaim
    metadata:
      creationTimestamp: "2019-10-24T13:30:07Z"
      finalizers:
      - objectbucket.io/finalizer
      generation: 2
      labels:
        app: noobaa
        bucket-provisioner: openshift-storage.noobaa.io-obc
        noobaa-domain: openshift-storage.noobaa.io
      name: test21obc
      namespace: openshift-storage
      resourceVersion: "40756"
      selfLink: /apis/objectbucket.io/v1alpha1/namespaces/openshift-storage/objectbucketclaims/test21obc
      uid: 64f04cba-f662-11e9-bc3c-0295250841af
    spec:
      ObjectBucketName: obc-openshift-storage-test21obc
      bucketName: test21obc-933348a6-e267-4f82-82f1-e59bf4fe3bb4
      generateBucketName: test21obc
      storageClassName: openshift-storage.noobaa.io
    status:
      phase: Bound
  4. openshift-storage 命名空间内,您可以找到配置映射和 secret 来使用此 Object Bucket Claim。CM 和 secret 的名称与 Object Bucket Claim 的名称相同。查看 secret:

    # oc get -n openshift-storage secret test21obc -o yaml

    输出示例:

    Example output:
    apiVersion: v1
    data:
      AWS_ACCESS_KEY_ID: c0M0R2xVanF3ODR3bHBkVW94cmY=
      AWS_SECRET_ACCESS_KEY: Wi9kcFluSWxHRzlWaFlzNk1hc0xma2JXcjM1MVhqa051SlBleXpmOQ==
    kind: Secret
    metadata:
      creationTimestamp: "2019-10-24T13:30:07Z"
      finalizers:
      - objectbucket.io/finalizer
      labels:
        app: noobaa
        bucket-provisioner: openshift-storage.noobaa.io-obc
        noobaa-domain: openshift-storage.noobaa.io
      name: test21obc
      namespace: openshift-storage
      ownerReferences:
      - apiVersion: objectbucket.io/v1alpha1
        blockOwnerDeletion: true
        controller: true
        kind: ObjectBucketClaim
        name: test21obc
        uid: 64f04cba-f662-11e9-bc3c-0295250841af
      resourceVersion: "40751"
      selfLink: /api/v1/namespaces/openshift-storage/secrets/test21obc
      uid: 65117c1c-f662-11e9-9094-0a5305de57bb
    type: Opaque

    该机密为您提供了 S3 访问凭据。

  5. 查看配置映射:

    # oc get -n openshift-storage cm test21obc -o yaml

    输出示例:

    apiVersion: v1
    data:
      BUCKET_HOST: 10.0.171.35
      BUCKET_NAME: test21obc-933348a6-e267-4f82-82f1-e59bf4fe3bb4
      BUCKET_PORT: "31242"
      BUCKET_REGION: ""
      BUCKET_SUBREGION: ""
    kind: ConfigMap
    metadata:
      creationTimestamp: "2019-10-24T13:30:07Z"
      finalizers:
      - objectbucket.io/finalizer
      labels:
        app: noobaa
        bucket-provisioner: openshift-storage.noobaa.io-obc
        noobaa-domain: openshift-storage.noobaa.io
      name: test21obc
      namespace: openshift-storage
      ownerReferences:
      - apiVersion: objectbucket.io/v1alpha1
        blockOwnerDeletion: true
        controller: true
        kind: ObjectBucketClaim
        name: test21obc
        uid: 64f04cba-f662-11e9-bc3c-0295250841af
      resourceVersion: "40752"
      selfLink: /api/v1/namespaces/openshift-storage/configmaps/test21obc
      uid: 651c6501-f662-11e9-9094-0a5305de57bb

    配置映射包含应用的 S3 端点信息。