K8s 里用 Ceph 做持久化存储是经典组合。RBD 走 CSI 是当前标准方案,但配起来坑很多。

整体架构

StorageClass --> PVC --> CSI Provisioner --> Ceph (创建 RBD image)
                       \
                        --> CSI Node Plugin --> rbd map (节点上)
                                            --> mount (容器看到)

部署 ceph-csi

helm repo add ceph-csi https://ceph.github.io/csi-charts
helm install ceph-csi-rbd ceph-csi/ceph-csi-rbd \
  --namespace ceph-csi-rbd --create-namespace \
  --set csiConfig[0].clusterID="<集群ID>" \
  --set csiConfig[0].monitors[0]="<mon1>:6789" \
  --set csiConfig[0].monitors[1]="<mon2>:6789"

集群 ID 从 ceph fsid 拿。

创建 StorageClass

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: csi-rbd-sc
provisioner: rbd.csi.ceph.com
parameters:
  clusterID: <fsid>
  pool: rbd
  imageFeatures: layering
  csi.storage.k8s.io/provisioner-secret-name: csi-rbd-secret
  csi.storage.k8s.io/provisioner-secret-namespace: ceph-csi-rbd
  csi.storage.k8s.io/node-stage-secret-name: csi-rbd-secret
  csi.storage.k8s.io/node-stage-secret-namespace: ceph-csi-rbd
reclaimPolicy: Delete
allowVolumeExpansion: true

imageFeatures: layering 必须只有 layering,多了内核 RBD 模块不支持会挂载失败。

几个典型坑

1. PVC 一直 Pending

describe pvc 通常看到 failed to provision volume with StorageClass。看 provisioner Pod 日志:

kubectl logs -n ceph-csi-rbd ceph-csi-rbd-provisioner-xxx -c csi-rbdplugin

最常见:secret 用户在 Ceph 上没权限。ceph auth get-or-create client.k8s mon 'profile rbd' osd 'profile rbd pool=rbd' 给权限。

2. Pod 起来 mount 失败

MountVolume.MountDevice failed for volume "xxx" : rpc error

节点上看 rbd 映射:

rbd showmapped
dmesg | tail

经常是 kernel rbd 模块 features 不支持(如 fast-diff、object-map 没关)。

3. 节点重启后 mount 不回来

CSI plugin 重启后会自动恢复,但如果 plugin 自己挂了就麻烦。建议给 plugin DaemonSet 加 priorityClass: system-node-critical

4. 扩容 PVC 卡住

PVC 改 size 后状态长期 Resizing

  • 检查 RBD image 是否真的扩了:rbd info rbd/csi-vol-xxx
  • 文件系统扩展需要 Pod 内执行(CSI 一般自动做 xfs_growfs,但 ext4 偶尔不灵)

监控指标

ceph-csi 自带 prometheus exporter,关键指标:

  • csi_operations_seconds:操作耗时
  • csi_operation_errors_total:错误数
  • rbd_image_count:当前管理的 image 数

教训:CSI 出问题先看 provisioner Pod 日志,再看节点 rbd 映射,再去 Ceph 集群查 auth。

标签: none

添加新评论