Resize a PersistentVolumeClaim (PVC) for Postgres that supports volume expansion, on
native Kubernetes.
About this task
You can expand a PVC if your storage provisioner supports volume expansion. This procedure is for
use on native Kubernetes.
Note: This procedure is for use only with Postgres.
Procedure
- Determine the primary Postgres pod.
kubectl get pods --selector role=master | grep -v bootstrapselector=role=master
- Gracefully shutdown Postgres pods.
- Exec into the Postgres primary pod.
kubectl exec -it <postgres-pod> -- bash
- Pause Patroni process. Note: you can skip this step if using the one replica profile.
- Stop the Postgres process gracefully.
pg_ctl stop -D /pgdata/<cluster-name>
For example:
- Determine the PVC linked to the primary Postgres pod, and obtain the
claimName
of the PVC.
kubectl get pod <postgres-pod> -o json | jq '.spec.volumes[] | select ( has ("persistentVolumeClaim"))'
- Scale down the Postgres deployment.
kubectl get deploy | grep postgres | grep -v bouncer | grep -v bootstrap | grep -v backrest | grep -v operator
If you are using n3
profile then you find 3 deployments. Scale them down:
kubectl scale deploy <deployment-name> --replicas=0
- Edit the PVC you want to increase.
kubectl edit pvc <claimName>
- Update
spec.resources.requests.storage
field value with new size. For
example:
spec:
resources:
requests:
storage: 20Gi
- Scale up the Postgres deployment.
kubectl get deploy | grep postgres | grep -v bouncer | grep -v bootstrap | grep -v backrest | grep -v operator
If you are using the n3
profile then you find 3 deployments. Scale them up:
kubectl scale deploy <deployment-name> --replicas=1
- If using the
n3
profile, resume the Patroni process. If using the
n1
profile, skip this step.
-
Identify the Postgres pods.
kubectl get pods --selector role
-
Exec into any Postgres pod.
kubectl exec -it <postgres-pod> -- bash
-
Resume Patroni.