k8s ceph pv pvc 动态扩容

问题

目的:初始配置pv和pvc的容量小了,想要进行动态扩容
修改pvc配置,其它无操作
kubectl edit PersistentVolumeClaim harbor-harbor-jobservice -n harbor
修改spec. resources.requests.storage: 4Gi -> 8G

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    field.cattle.io/creatorId: u-ou7462szpa
    pv.kubernetes.io/bind-completed: "yes"
    pv.kubernetes.io/bound-by-controller: "yes"
    volume.beta.kubernetes.io/storage-provisioner: kubernetes.io/rbd
  creationTimestamp: 2021-07-08T08:30:48Z
  finalizers:
  - kubernetes.io/pvc-protection
  labels:
    cattle.io/creator: norman
  name: harbor-harbor-jobservice
  namespace: harbor
  resourceVersion: "161333541"
  selfLink: /api/v1/namespaces/harbor/persistentvolumeclaims/harbor-harbor-jobservice
  uid: cc1dd2bf-dfc6-11eb-b173-eeeeeeeeeeee
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi
  storageClassName: ceph
  volumeMode: Filesystem
  volumeName: pvc-cc1dd2bf-dfc6-11eb-b173-eeeeeeeeeeee

pvc报错如下,一致报错,循环报错

(combined from similar events): error expanding volume "harbor/harbor-harbor-jobservice" of plugin
 "kubernetes.io/rbd": rbd info failed, error: parse rbd info output failed: 2021-07-16 14:52:20.796586
 7f4b275c2100 -1 did not load config file, using default settings. 2021-07-16 14:52:20.951187 7f4b275c2100
 -1 auth: unable to find a keyring on
 /etc/ceph/ceph.client.admin.keyring,/etc/ceph/ceph.keyring,/etc/ceph/keyring,/etc/ceph/keyring.bin: (2) No
 such file or directory {"name":"kubernetes-dynamic-pvc-ccf922de-dfc6-11eb-ad4e-
eeeeeeeeeeee","size":2147483648,"objects":512,"order":22,"object_size":4194304,"block_name_prefix":"rbd_
data.18f26a6b8b4567","format":2,"features":["layering"],"flags":[]}, invalid character '-' after top-level value

解决

1、kubectl edit storageclass ceph 确保allowVolumeExpansion: true
2、确定文件系统类型,只有卷中包含的文件系统是 XFS、Ext3 或者 Ext4 时,你才可以重设卷的大小
3、检查卷使用模式:当卷中包含文件系统时,只有在 Pod 使用 ReadWrite 模式来使用 PVC 申领的情况下才能重设其文件系统的大小。
4、上述修改完pvc配置,与之对应的pv配置也要相应修改
5、重启pod:文件系统扩充的操作或者是在 Pod 启动期间完成,或者在下层文件系统支持在线 扩充的前提下在 Pod 运行期间完成。

补充:

说明: Kubernetes 从 1.15 版本开始将调整使用中 PVC 申领大小这一能力作为 Beta 特性支持;该特性在 1.11 版本以来处于 Alpha 阶段。 ExpandInUsePersistentVolumes 特性必须被启用;在很多集群上,与此类似的 Beta 阶段的特性是自动启用的。
在这种情况下,你不需要删除和重建正在使用某现有 PVC 的 Pod 或 Deployment。 所有使用中的 PVC 在其文件系统被扩充之后,立即可供其 Pod 使用。 此功能特性对于没有被 Pod 或 Deployment 使用的 PVC 而言没有效果。 你必须在执行扩展操作之前创建一个使用该 PVC 的 Pod。
本集群版本 Server GitVersion:"v1.14.6",无法使用上述特性

处理扩充卷过程中的失败,重新使用旧的pv对象

如果扩充下层存储的操作失败,集群管理员可以手动地恢复 PVC 申领的状态并 取消重设大小的请求。否则,在没有管理员干预的情况下,控制器会反复重试 重设大小的操作。

  1. 将绑定到 PVC 申领的 PV 卷标记为 Retain 回收策略;
  2. 删除 PVC 对象。由于 PV 的回收策略为 Retain,我们不会在重建 PVC 时丢失数据。
  3. 删除 PV 规约中的 claimRef 项,这样新的 PVC 可以绑定到该卷。 这一操作会使得 PV 卷变为 "可用(Available)"。
  4. 使用小于等于PV 卷大小的尺寸重建 PVC,设置 PVC 的 volumeName 字段为 PV 卷的名称。 这一操作将把新的 PVC 对象绑定到现有的 PV 卷。
  5. 不要忘记恢复 PV 卷上设置的回收策略。

参考
https://kubernetes.io/zh/docs/concepts/storage/persistent-volumes/#expanding-persistent-volumes-claims

你可能感兴趣的:(k8s ceph pv pvc 动态扩容)