为什么 File Storage for VPC 部署由于许可权错误而失败?
虚拟私有云
使用 File Storage for VPC 的应用程序失败,发生许可权错误。
您创建了自己的存储类以用于现有文件共享,但未指定正确的 uid
和 gid
。 当进程在 UNIX 和 Linux 上运行时,操作系统用用户 ID(UID)识别用户,用组 ID(GID)识别组。 这些标识确定用户或组可访问的系统资源。 例如,如果文件存储器用户标识为 12345,其组标识为 6789,那么主机节点和容器中的安装必须具有相同的标识。 容器的主进程必须与其中一个或两个标识匹配才能访问文件共享。
您可以通过以下方式之一解决该问题。
-
如果需要应用程序以非 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-DEPLOYMENT
apiVersion: 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
-
将更改应用于部署。