6.6.2. ボリュームポピュレーターの作成


ボリュームポピュレーターを作成して使用するには、以下を実行します。

  1. ボリュームポピュレーター用のカスタムリソース定義 (CRD) を作成します。
  2. ボリュームポピュレーターを使用して、データが事前にロードされたボリュームを作成します。

6.6.2.1. ボリュームポピュレーターの CRD の作成

次の手順では、ボリュームポピュレーターの "hello, world" カスタムリソース定義 (CRD) の例を作成する方法について説明します。

ユーザーは、この CRD のインスタンスを作成し、永続ボリューム要求 (PVC) に対してデータを事前に投入できます。

前提条件

  • OpenShift Container Platform Web コンソールにアクセスできる。
  • クラスター管理者権限でクラスターにアクセスできる。

手順

  1. 次のサンプル YAML ファイルを使用して、ポピュレーターおよび関連リソースの論理グループと操作の namespace を作成します。

    namespace YAML ファイルの例

    apiVersion: v1
    kind: Namespace
    metadata:
      name: hello

  2. 次のサンプル YAML ファイルを使用して、データソースの CRD を作成します。

    CRD YAML ファイルの例

    apiVersion: apiextensions.k8s.io/v1
    kind: CustomResourceDefinition
    metadata:
      name: hellos.hello.example.com
    spec:
      group: hello.example.com
      names:
        kind: Hello
        listKind: HelloList
        plural: hellos
        singular: hello
      scope: Namespaced
      versions:
      - name: v1alpha1
        schema:
          openAPIV3Schema:
            description: Hello is a specification for a Hello resource
            properties:
              apiVersion:
                description: 'APIVersion defines the versioned schema of this representation
                  of an object. Servers should convert recognized schemas to the latest
                  internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
                type: string
              kind:
                description: 'Kind is a string value representing the REST resource this
                  object represents. Servers may infer this from the endpoint the client
                  submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
                type: string
              spec:
                description: HelloSpec is the spec for a Hello resource
                properties:
                  fileContents:
                    type: string
                  fileName:
                    type: string
                required:
                - fileContents
                - fileName
                type: object
            required:
            - spec
            type: object
        served: true
        storage: true

  3. ServiceAccountClusterRoleClusterRoleBindering、および Deployment を作成してコントローラーをデプロイし、データの事前投入を実装するロジックを実行します。

    1. 次のサンプル YAML ファイルを使用して、ポピュレーターのサービスアカウントを作成します。

      サービスアカウント YAML ファイルの例

      apiVersion: v1
      kind: ServiceAccount
      metadata:
        name: hello-account
        namespace: hello 
      1

      1
      先ほど作成した namespace を参照します。
    2. 次のサンプル YAML ファイルを使用して、ポピュレーターのクラスターロールを作成します。

      クラスターロールの YAML ファイルの例

      kind: ClusterRole
      apiVersion: rbac.authorization.k8s.io/v1
      metadata:
        name: hello-role
      rules:
        - apiGroups: [hello.example.com]
          resources: [hellos]
          verbs: [get, list, watch]

    3. 次のサンプル YAML ファイルを使用して、クラスターロールバインディングを作成します。

      クラスターロールバインディングの YAML ファイルの例

      kind: ClusterRoleBinding
      apiVersion: rbac.authorization.k8s.io/v1
      metadata:
        name: hello-binding 
      1
      
      subjects:
        - kind: ServiceAccount
          name: hello-account 
      2
      
          namespace: hello 
      3
      
      roleRef:
        kind: ClusterRole
        name: hello-role 
      4
      
        apiGroup: rbac.authorization.k8s.io

      1
      ロールバインディングの名前。
      2
      先ほど作成したサービスアカウントの名前を参照します。
      3
      先ほど作成したサービスアカウントの namespace の名前を参照します。
      4
      先ほど作成したクラスターロールを参照します。
    4. 次のサンプル YAML ファイルを使用して、ポピュレーターのデプロイメントを作成します。

      デプロイメント YAML ファイルの例

      kind: Deployment
      apiVersion: apps/v1
      metadata:
        name: hello-populator
        namespace: hello 
      1
      
      spec:
        selector:
          matchLabels:
            app: hello
        template:
          metadata:
            labels:
              app: hello
          spec:
            serviceAccount: hello-account 
      2
      
            containers:
              - name: hello
                image: registry.k8s.io/sig-storage/hello-populator:v1.0.1
                imagePullPolicy: IfNotPresent
                args:
                  - --mode=controller
                  - --image-name=registry.k8s.io/sig-storage/hello-populator:v1.0.1
                  - --http-endpoint=:8080
                ports:
                  - containerPort: 8080
                    name: http-endpoint
                    protocol: TCP

      1
      先ほど作成した namespace を参照します。
      2
      先ほど作成したサービスアカウントを参照します。
  4. 次のサンプル YAML ファイルを使用して、ボリュームポピュレーターを作成し、kind:Hello リソースをボリュームの有効なデータソースとして登録します。

    ボリュームポピュレーターの YAML ファイルの例

    kind: VolumePopulator
    apiVersion: populator.storage.k8s.io/v1beta1
    metadata:
      name: hello-populator 
    1
    
    sourceKind:
      group: hello.example.com
      kind: Hello

    1
    ボリュームポピュレーターの名前。

    未登録のポピュレーターを使用する PVC は、"The datasource for this PVC does not match any registered VolumePopulator" というイベントを作成します。これは、未知 (未登録) ポピュレーターを使用しているため、PVC がプロビジョニングされない可能性があることを示します。

次のステップ

  • これで、この CRD の CR インスタンスを作成して PVC にデータを事前投入できるようになりました。

ボリュームポピュレーターを使用してボリュームにデータを事前投入する方法については、ボリュームポピュレーターを使用してデータが事前投入されたボリュームを作成する を参照してください。

Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

Red Hat ドキュメントについて

Legal Notice

Theme

© 2026 Red Hat
トップに戻る