為何我的 File Storage for VPC 部署會因許可權錯誤而失敗?
虛擬私有雲
您的應用程式在使用 File Storage for VPC 時,因權限錯誤而發生錯誤。
排除 VPC 檔案儲存中非 root 使用者存取問題。
您已建立自己的儲存空間類別以與現有檔案共用搭配使用,但未指定正確的 uid 及 gid。 當程序在 UNIX 和 Linux 上執行時,作業系統會透過使用者識別碼 (UID) 來識別使用者,並透過群組識別碼 (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 設定檔。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 -
將變更套用至部署。