2

我正在尝试创建一个动态 Azure 磁盘卷以在具有特定权限要求的 pod 中使用。

该容器在用户 id 下运行472,因此我需要找到一种方法来为该用户(至少)安装具有 rw 权限的卷。

StorageClass定义如下

apiVersion: storage.k8s.io/v1
kind: StorageClass
provisioner: kubernetes.io/azure-disk
reclaimPolicy: Delete
volumeBindingMode: Immediate
metadata:
  name: foo-storage
mountOptions:
  - rw
parameters:
  cachingmode: None
  kind: Managed
  storageaccounttype: Standard_LRS

还有这个PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: foo-storage
  namespace: foo
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: foo-storage
  resources:
    requests:
      storage: 1Gi

我可以在 pod 中运行以下命令:

containers:
  - image: ubuntu
    name: foo
    imagePullPolicy: IfNotPresent
    command:
      - ls
      - -l
      - /var/lib/foo
    volumeMounts:
      - name: foo-persistent-storage
        mountPath: /var/lib/foo
volumes:
  - name: foo-persistent-storage
    persistentVolumeClaim:
      claimName: foo-storage

吊舱将正确安装并启动,但kubectl logs <the-pod>会显示

total 24
drwxr-xr-x 3 root root  4096 Nov 23 11:42 .
drwxr-xr-x 1 root root  4096 Nov 13 12:32 ..
drwx------ 2 root root 16384 Nov 23 11:42 lost+found

即当前目录被挂载root为所有其他用户所有并且只读。

我已经尝试向 中添加一个mountOptions部分StorageClass,但是无论我尝试什么(uid=472user=472),我都会在启动时遇到安装错误,例如

mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/plugins/kubernetes.io/azure-disk/mounts/m1019941199 --scope -- mount -t ext4 -o group=472,rw,user=472,defaults /dev/disk/azure/scsi1/lun0 /var/lib/kubelet/plugins/kubernetes.io/azure-disk/mounts/m1019941199
Output: Running scope as unit run-r7165038756bf43e49db934e8968cca8b.scope.
mount: wrong fs type, bad option, bad superblock on /dev/sdc,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.

我也尝试从man mount获取一些信息,但我没有找到任何有效的方法。

如何配置此存储类、持久卷声明和卷挂载,以便运行容器进程的非 root 用户有权在挂载路径中写入(并创建子目录)?

4

1 回答 1

1

您需要securityContext像下面这样定义您的 pod 规范,以便它与新运行的用户和组 ID 匹配:

securityContext:
  runAsUser: 472
  fsGroup: 472

稳定的 Grafana Helm Chart 也是如此。请参阅securityContext此处的配置:https ://github.com/helm/charts/tree/master/stable/grafana#configuration

于 2018-11-25T02:30:20.950 回答