Kubernetes 更改挂载卷的权限

Kubernetes changing permissions of mounted volumes

我在 Openstack 上管理 Kubernetes 部署。

我的用户 pods 安装一个 PersistentVolume 使用 Openstack Cinder 作为他们的主文件夹动态创建的。

奇怪的是,如果我创建一个文件权限为 600 的(空)文件:

bash-4.2$ ls -l
total 16
-rw------- 1 jovyan users     0 Jul 16 17:55 id_rsa

然后我杀死容器并重新启动它,卷再次安装,但权限现在有 rw 组权限:

bash-4.2$ ls -l
total 16
-rw-rw---- 1 jovyan users     0 Jul 16 17:55 id_rsa

关于如何进一步调试这个问题有什么建议吗?

Kubernetes 配置的详细信息

检查 Openstack

我一开始以为是 Openstack 的问题,但如果我从 Openstack 实例中分离卷,然后使用 Openstack 命令再次附加它,并使用终端将它挂载到节点上,权限就可以了。所以我认为是 Kubernetes 以某种方式弄乱了权限。

Yaml 资源

我在要点上粘贴了 pod、PV 和 PVC 的 YAML 文件,参见 https://gist.github.com/zonca/21b81f735d0cc9a06cb85ae0fa0285e5

我还为这些资源添加了 kubectl describe 的输出。 它是 Jupyterhub 0.9.0 Helm 包的部署。

发生这种情况是因为您已使用 fsGroup 配置了您的 pod。它在 securityContext:

下指定
---
securityContext:
  fsGroup: 100
---

每当指定fsGroup字段时,容器的所有进程也是补充组ID的一部分。卷的所有者和在该卷中创建的任何文件都将是组 ID。

kubernetes API docs 解释如下:

fsGroup is a special supplemental group that applies to all containers in a pod. Some volume types allow the Kubelet to change the ownership of that volume to be owned by the pod:

  1. The owning GID will be the FSGroup
  2. The setgid bit is set (new files created in the volume will be owned by FSGroup)
  3. The permission bits are OR'd with rw-rw---- If unset, the Kubelet will not modify the ownership and permissions of any volume.