3.10. hostPath を使用した永続ストレージ

OpenShift Container Platform クラスター内の hostPath ボリュームは、ファイルまたはディレクトリーをホストノードのファイルシステムから Pod にマウントします。ほとんどの Pod には hostPath ボリュームは必要ありませんが、アプリケーションが必要とする場合は、テスト用のクイックオプションが提供されます。

重要

クラスター管理者は、特権付き Pod として実行するように Pod を設定する必要があります。これにより、同じノードの Pod へのアクセスが付与されます。

3.10.1. 概要

OpenShift Container Platform は単一ノードクラスターでの開発およびテスト用の hostPath マウントをサポートします。

実稼働クラスターでは、hostPath を使用しません。代わりにクラスター管理者は、GCE Persistent Disk ボリューム、NFS 共有、Amazon EBS ボリュームなどのネットワークリソースをプロビジョニングします。ネットワークリソースは、StorageClass を使用した動的プロビジョニングの設定をサポートします。

hostPath ボリュームは静的にプロビジョニングする必要があります。

3.10.2. hostPath ボリュームの静的プロビジョニング

hostPath ボリュームを使用する Pod は、手動の (静的) プロビジョニングで参照される必要があります。

手順

  1. 永続ボリューム (PV) を定義します。PersistentVolume オブジェクト定義を使用して pv.yaml ファイルを作成します。

      apiVersion: v1
      kind: PersistentVolume
      metadata:
        name: task-pv-volume 1
        labels:
          type: local
      spec:
        storageClassName: manual 2
        capacity:
          storage: 5Gi
        accessModes:
          - ReadWriteOnce 3
        persistentVolumeReclaimPolicy: Retain
        hostPath:
          path: "/mnt/data" 4
    1
    ボリュームの名前。この名前は PersistentVolumeClaim または Pod で識別されるものです。
    2
    PersistentVolumeClaim 要求をこの PersistentVolume にバインドするために使用されます。
    3
    ボリュームは単一ノードで read-write としてマウントできます。
    4
    設定ファイルでは、ボリュームがクラスターのノードの /mnt/data にあるように指定します。
  2. ファイルから PV を作成します。

    $ oc create -f pv.yaml
  3. Persistent Volume Claim (永続ボリューム要求、PVC) を定義します。PersistentVolumeClaim オブジェクト定義を使用して、ファイル pvc.yaml を作成します。

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: task-pvc-volume
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
      storageClassName: manual
  4. ファイルから PVC を作成します。

    $ oc create -f pvc.yaml

3.10.3. 特権付き Pod での hostPath 共有のマウント

PersistentVolumeClaim の作成後に、これをアプリケーション内で使用できます。以下の例は、この共有を Pod 内にマウントする方法を示しています。

前提条件

  • 基礎となる hostPath 共有にマップされる PersistentVolumeClaim があること。

手順

  • 既存の PersistentVolumeClaim をマウントする特権付き Pod を作成します。

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-name 1
    spec:
      containers:
        ...
        securityContext:
          privileged: true 2
        volumeMounts:
        - mountPath: /data 3
          name: hostpath-privileged
      ...
      securityContext: {}
      volumes:
        - name: hostpath-privileged
          persistentVolumeClaim:
            claimName: task-pvc-volume 4
    1
    Pod の名前。
    2
    Pod はノードのストレージにアクセスするために特権付きとして実行される必要があります。
    3
    特権付き Pod 内に hostPath 共有をマウントするパス。
    4
    以前に作成された PersistentVolumeClaim の名前。