許可エラーが原因で File Storage for VPC のデプロイメントが失敗するのはなぜですか?
仮想プライベートクラウド
File Storage for VPC を使用しているアプリが、権限に関するエラーで正常に動作しません。
VPC ファイルストレージにおける非 root ユーザーによるアクセスに関する問題のトラブルシューティング。
既存のファイル共有で使用する独自のストレージ・クラスを作成しましたが、正しい uid および gid を指定しませんでした。 UNIXおよび Linux 上でプロセスが実行される際、オペレーティングシステムはユーザーをユーザーID(UID)で、グループをグループID(GID)で識別します。 これらの ID は、ユーザーまたはグループがアクセスできるシステム・リソースを決定します。 たとえば、ファイルストレージのユーザーIDが12345で、グループIDが6789の場合、ホストノードおよびコンテナ内でのマウントには、これらと同じIDを設定する必要があります。
ファイル共有にアクセスするには、コンテナーのメイン・プロセスがこれらの ID のいずれかまたは両方に一致する必要があります。
この問題は、以下のいずれかの方法で解決できます。
-
アプリを非 root として実行する必要がある場合は、アプリが必要とする正しい
uidとgidを使用して独自のストレージ・クラスを作成します。 -
アプリをrootユーザーとして実行したい場合は、
fsGroup: 0を使用するようにデプロイ設定を編集してください。
独自のストレージ・クラスを作成し、アプリに必要な uid と gid を指定します。
静的プロビジョニングで File Storage for VPC を使用する場合は、正しい uid および gid を参照する必要があります。
-
アプリが必要とする正しい
uidおよびgidを使用してストレージ・クラスを作成します。 ストレージ・プロファイルのリストについては、 File Storage for VPC profilesを 参照のこと。apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: custom-storageclas provisioner: vpc.file.csi.ibm.io mountOptions: - hard - nfsvers=4.0 - sec=sys parameters: profile: "custom-iops" # The VPC Storage profile used. iops: "400" # Default IOPS. User can override from secrets billingType: "hourly" # The default billing policy used. User can override this default encrypted: "false" # By default, all PVC using this class will only be provider managed encrypted. The user can override this default encryptionKey: "" # If encrypted is true, then a user must specify the encryption key used associated KP instance resourceGroup: "" # Use resource group if specified here. Otherwise, use the one mentioned in storage-secrete-store zone: "" # By default, the storage vpc driver will select a zone. The user can override this default tags: "" # A list of tags "a, b, c" that will be created when the volume is created. This can be overidden by user classVersion: "1" uid: "1234" # The initial user identifier for the file share. gid: "5678" # The initial group identifier for the file share. reclaimPolicy: "Delete" allowVolumeExpansion: true -
カスタマイズしたストレージ・クラスをクラスターに作成します。
oc apply -f custom-storageclass.yaml -
ストレージ・クラスがクラスター内に存在することを確認します。
oc get sc出力例
NAME PROVISIONER ibmc-vpc-file-10iops-tier vpc.file.csi.ibm.io ibmc-vpc-file-3iops-tier vpc.file.csi.ibm.io ibmc-vpc-file-5iops-tier vpc.file.csi.ibm.io ibmc-vpc-file-retain-10iops-tier vpc.file.csi.ibm.io ibmc-vpc-file-retain-3iops-tier vpc.file.csi.ibm.io ibmc-vpc-file-retain-5iops-tier vpc.file.csi.ibm.io ibmc-vpc-file-custom vpc.file.csi.ibm.io
fsGroup: 0 を使用して root として実行するようにアプリを編集します。
-
クラスターにログインします。
-
編集するクラスター内のデプロイメントを識別します。
kubectl get deployments -
デプロイメントの
securityContextセクションにfsGroup: 0を追加して、デプロイメントを編集します。kubectl get deployment -o yaml YOUR-DEPLOYMENTapiVersion: apps/v1 kind: Deployment metadata: name: <deployment_name> labels: app: <deployment_label> spec: securityContext: fsGroup: 0 selector: matchLabels: app: <app_name> template: metadata: labels: app: <app_name> spec: containers: - image: <image_name> name: <container_name> volumeMounts: - name: <volume_name> mountPath: /<file_path> volumes: - name: <volume_name> persistentVolumeClaim: claimName: PVC-NAME -
変更をデプロイメントに適用します。