Rancher Monitoring V2 Prometheus PVC 扩容

根据 Prometheus Operator 官方文档 描述,即使 StorageClass 支持调整大小,Kubernetes(目前)也不支持通过 StatefulSets 扩展卷。这意味着在更新 Prometheus 等自定义资源的 spec.storage 字段中的存储请求时,Operator 必须删除/创建底层的 StatefulSet,而相关的 PVC 不会扩展。

可以通过下面的步骤进行手动扩容。

  1. 首先需要检查 StorageClass 支不支持 volume 的扩容:
1
kubectl get storageclass <storageclass_name> -o custom-columns=NAME:.metadata.name,ALLOWVOLUMEEXPANSION:.allowVolumeExpansion
  1. 在 Rancher 更新 Helm Chart 的 values,将存储大小改成需要的值,再通过 Yaml 编辑将 Prometheus 的 paused 改成 true(需要注意 Yaml 中多处存在 paused 的配置,需要改的是 Prometheus 的):

等待更新完成后,通过下面的命令检查是否更新成功:

1
kubectl -n cattle-monitoring-system get prometheus rancher-monitoring-prometheus -oyaml | grep -E "paused|storage"
  1. 手动更新 PVC 的存储值:
1
kubectl -n cattle-monitoring-system patch pvc/prometheus-rancher-monitoring-prometheus-db-prometheus-rancher-monitoring-prometheus-0 --patch '{"spec": {"resources": {"requests": {"storage":"10Gi"}}}}'
  1. 删除 StatefulSet:
1
kubectl -n cattle-monitoring-system delete statefulset -l operator.prometheus.io/name=rancher-monitoring-prometheus --cascade=orphan
  1. 在 Rancher 更新 Helm Chart 的 values,通过 Yaml 编辑将 Prometheus 的 paused 改回 false,更新完毕之后 Operator 就会重新生成 StatefulSet:

  1. 检查是否扩容成功,检查 Prometheus 和 StatefulSet 以及 PVC 数据是否一致:
1
2
3
4
kubectl -n cattle-monitoring-system get prometheus rancher-monitoring-prometheus -oyaml | grep -E "paused|storage"
kubectl -n cattle-monitoring-system get sts prometheus-rancher-monitoring-prometheus -oyaml | grep "storage:"
kubectl -n cattle-monitoring-system get pvc prometheus-rancher-monitoring-prometheus-db-prometheus-rancher-monitoring-prometheus-0
kubectl -n cattle-monitoring-system exec -it prometheus-rancher-monitoring-prometheus-0 -- df -h /prometheus

Author

Warner Chen

Posted on

2025-02-10

Updated on

2025-02-27

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.