6.6.2. ボリュームポピュレーターの作成
ボリュームポピュレーターを作成して使用するには、以下を実行します。
- ボリュームポピュレーター用のカスタムリソース定義 (CRD) を作成します。
- ボリュームポピュレーターを使用して、データが事前にロードされたボリュームを作成します。
6.6.2.1. ボリュームポピュレーターの CRD の作成 リンクのコピーリンクがクリップボードにコピーされました!
次の手順では、ボリュームポピュレーターの "hello, world" カスタムリソース定義 (CRD) の例を作成する方法について説明します。
ユーザーは、この CRD のインスタンスを作成し、永続ボリューム要求 (PVC) に対してデータを事前に投入できます。
前提条件
- OpenShift Container Platform Web コンソールにアクセスできる。
- クラスター管理者権限でクラスターにアクセスできる。
手順
次のサンプル YAML ファイルを使用して、ポピュレーターおよび関連リソースの論理グループと操作の namespace を作成します。
namespace YAML ファイルの例
apiVersion: v1 kind: Namespace metadata: name: hello次のサンプル 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: trueServiceAccount、ClusterRole、ClusterRoleBindering、およびDeploymentを作成してコントローラーをデプロイし、データの事前投入を実装するロジックを実行します。次のサンプル YAML ファイルを使用して、ポピュレーターのサービスアカウントを作成します。
サービスアカウント YAML ファイルの例
apiVersion: v1 kind: ServiceAccount metadata: name: hello-account namespace: hello1 - 1
- 先ほど作成した namespace を参照します。
次のサンプル 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]次のサンプル YAML ファイルを使用して、クラスターロールバインディングを作成します。
クラスターロールバインディングの YAML ファイルの例
kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: hello-binding1 subjects: - kind: ServiceAccount name: hello-account2 namespace: hello3 roleRef: kind: ClusterRole name: hello-role4 apiGroup: rbac.authorization.k8s.io次のサンプル YAML ファイルを使用して、ポピュレーターのデプロイメントを作成します。
デプロイメント YAML ファイルの例
kind: Deployment apiVersion: apps/v1 metadata: name: hello-populator namespace: hello1 spec: selector: matchLabels: app: hello template: metadata: labels: app: hello spec: serviceAccount: hello-account2 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
次のサンプル YAML ファイルを使用して、ボリュームポピュレーターを作成し、
kind:Helloリソースをボリュームの有効なデータソースとして登録します。ボリュームポピュレーターの YAML ファイルの例
kind: VolumePopulator apiVersion: populator.storage.k8s.io/v1beta1 metadata: name: hello-populator1 sourceKind: group: hello.example.com kind: Hello- 1
- ボリュームポピュレーターの名前。
未登録のポピュレーターを使用する PVC は、"The datasource for this PVC does not match any registered VolumePopulator" というイベントを作成します。これは、未知 (未登録) ポピュレーターを使用しているため、PVC がプロビジョニングされない可能性があることを示します。
次のステップ
- これで、この CRD の CR インスタンスを作成して PVC にデータを事前投入できるようになりました。
ボリュームポピュレーターを使用してボリュームにデータを事前投入する方法については、ボリュームポピュレーターを使用してデータが事前投入されたボリュームを作成する を参照してください。