根据kubegres的这个issue,目前kubegres无法自动扩容,只能手动的patch部署文件。将这个过程摘抄如下:

假定kubegres部署在默认的kubegres-system命名空间中,postgres集群部署在postgres-cluster命名空间中,postgres-1primary节点,postgres-2postgres-3分别为两个replica节点

1. disable kubegres operator:

1
kubectl scale -n kubegres-system --replicas=0 deployment.apps/kubegres-controller-manager 

为了防止后续对kubegres operator部署的statefulset资源进行操作时,kubegres operator同时对该资源进行操作,所以要先关闭所有的kubegres operator

2. check if kubegres controller deployment is scaled down to 0

1
kubectl get -n kubegres-system deployment kubegres-controller-manager 

3. export kubegres statefulset manifest

1
kubectl get -n postgres-cluster sts postgres-1 -o yaml > postgres-1.yaml

4. edit pvc size in exported manifest and replace statefulset with it

修改生成的yaml文件中的pvc-size这一项到要扩展的pvc大小,并替换

1
kubectl replace --force -f postgres-1.yaml

5. scale down statefulset

1
kubectl scale -n postgres-cluster --replicas=0 sts postgres-1

6. resize PVC

我这边用的是longhorn,可以直接在web页面选中对应的PVC,然后选择Expand即可扩容,等待其扩容完毕,其他方式可以参考 https://kubernetes.io/blog/2018/07/12/resizing-persistent-volumes-using-kubernetes/

7. scale back statefulset

1
kubectl scale -n postgres-cluster --replicas=1 sts postgres-1

8. wait for pod(s) to start in statefulset

9. repeat 3-7 with all kubegres statefulsets

10. modify size in your kind: Kubegres manifest in git or wherever you store your manifests

11. enable kubegres operator

1
kubectl scale --replicas=1 deployment.apps/kubegres-controller-manager -n kubegres-system