google-cloud-platform - GKE:使用基于 GCP 永久磁盘的只读 PV 时,无法以只读方式挂载 /dev/sdb
问题描述
我正在尝试将基于现有 GCP 永久磁盘的 PV 作为只读方式安装到我的 pod 上。我的配置看起来像这样(为了保密,它们的一部分被屏蔽了)
apiVersion: v1
kind: PersistentVolume
metadata:
name: data-and-models-pv
namespace: lipsync
spec:
storageClassName: ""
capacity:
storage: 10Gi
accessModes:
- ReadOnlyMany
claimRef:
namespace: lipsync
name: data-and-models-pvc
# csi:
# driver: pd.csi.storage.gke.io
# volumeHandle: projects/***/zones/***/disks/g-lipsync-data-and-models
gcePersistentDisk:
pdName: g-lipsync-data-and-models
fsType: ext4
readOnly: true
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-and-models-pvc
namespace: lipsync
spec:
storageClassName: ""
accessModes:
- ReadOnlyMany
resources:
requests:
storage: 10Gi
然后,在 pod 定义中:
volumeMounts:
- mountPath: /app/models
subPath: models
name: data-and-models-v
readOnly: true
- [...]
volumes:
- name: data-and-models-v
persistentVolumeClaim:
claimName: data-and-models-pvc
readOnly: true
但是,当我执行 kubectl apply 时,永远不会创建 pod,我遇到了这个事件:
0s Warning FailedMount pod/lipsync-api-67c784dfb7-4tlln MountVolume.MountDevice failed for volume "data-and-models-pv" : rpc error: code = Internal desc = Failed to format and mount device from ("/dev/disk/by-id/google-g-lipsync-data-and-models") to ("/var/lib/kubelet/plugins/kubernetes.io/csi/pv/data-and-models-pv/globalmount") with fstype ("ext4") and options ([]): mount failed: exit status 32
Mounting command: mount
Mounting arguments: -t ext4 -o defaults /dev/disk/by-id/google-g-lipsync-data-and-models /var/lib/kubelet/plugins/kubernetes.io/csi/pv/data-and-models-pv/globalmount
Output: mount: /var/lib/kubelet/plugins/kubernetes.io/csi/pv/data-and-models-pv/globalmount: cannot mount /dev/sdb read-only.
如果我手动 ssh 到充当支持 pod 的节点的 VM,我可以观察到在挂载选项中添加 noload 可以使我成功挂载磁盘:
sudo mount -o ro,noload,defaults /dev/sdb .
但我不知道有什么方法可以让 Kubernetes 使用这个额外的挂载选项。
如何成功让 GKE 将此磁盘挂载到我的 pod?
解决方案
今天我在只读模式下遇到了同样的问题。希望我的经历能给你一些想法。
我有两个快照,一个是别人创建的,另一个是我创建的。两个磁盘上的文件是相同的。
但是当我安装由另一个创建的屏幕截图配置的磁盘时,readOnly
工作正常。但我的只是不断收到与您相同的错误。
于是我在没有readOnly
模式的情况下登录了pod,看看这两个磁盘的区别。我发现的唯一区别是好的有userId: 1003
和groupId 1004
我的是root:root
。所以我跑到chown 1003:1004 -R ./
我的磁盘上,用它来创建一个新的快照,然后它运行得很顺利......
我还没有找到原因,但至少它起作用了。如果我弄清楚了,会告诉你的。
推荐阅读
- r - 在R中的多维数组上使用apply
- excel - 如何让我的函数引用列中正在使用的所有单元格,而不仅仅是一个广泛的函数?
- javascript - 如何在 koa 中使用带有 router.verb() 的中间件
- java - 如何在 Haskell 中创建二维数组?
- azure-resource-manager - 无法评估语言表达式属性“0”,属性名称必须是字符串 - 添加 Key Vault 访问策略时出现 ARM 模板错误
- osmnx - OSMNx - 我是否有可能从节点获得最短路径但没有边缘连接到它?
- python - pyomo 优化中的“searchsorted”查找
- python - 动态创建 SciPy curve_fit 函数
- ada - 对 ARM 裸机开发板的 GNAT 支持
- c++ - 为什么表达式的return语句会调用复制构造函数?