hack/setup_external_dev_services: Improve postgresql installation

The postgresql helm chart requires the cluster to provide a PersistentVolume
and places a PersisentVolumeClaim for this.
Ensure that the cluster provides PersistentVolumes.

Also set volumePermissions.enabled=true which helps to fix Permission denied
when trying to create the data directory in the PV mount directory
if the PV's permissions are not open enough:
https://github.com/bitnami/charts/issues/1210#issuecomment-1145923630
This commit is contained in:
root 2023-03-10 16:47:24 +01:00
parent 0b9174bfcd
commit 7911485063

View File

@ -31,9 +31,46 @@
# POSSIBILITY OF SUCH DAMAGE.
#
# TODO: Setup an bash error trap, to make errors from failing commands more
# visible and draw attention of the user to these errors.
# Install postgres
helm repo add bitnami https://charts.bitnami.com/bitnami
helm upgrade --install postgres bitnami/postgresql --set global.postgresql.auth.postgresPassword=postgres --set auth.postgresPassword=postgres --set auth.enablePostgresUser=true
# Documentation and source of the used chart with all configuration parameters:
# https://artifacthub.io/packages/helm/bitnami/postgresql
# https://github.com/helm/charts/tree/master/stable/postgresql
# The postgresql helm chart requires the cluster to provide a PersistentVolume
# and places a PersisentVolumeClaim for this.
# Ensure that the cluster provides PersistentVolumes:
if kubectl get PersistentVolume -o json
| jq -e '.items | .[].status | select(.phase == "Bound")' ; then
echo "Ok found at least one PersistentVolume"
else
echo "The postgresql helm chart has a PersistentVolumeClaim (PVC)."
echo "The cluster needs to provide at one PersistentVolume (PV) for this."
echo "For information how to create a PersistentVolume, see:"
echo "https://github.com/felipecruz91/k8s-postgresql-persistent-volume#create-persistent-volume"
exit 5
fi
# Note: The chart mounts the PV at persistence.mountPath,
# which defaults to /bitnami/postgresql and creates a directory /data in it.
# If it has no permission to create it, this error happens:
# mkdir: cannot create directory /bitnami/postgresql/data: Permission denied
# https://github.com/bitnami/charts/issues/1210
#
# Adding --set volumePermissions.enabled=true helps:
# https://github.com/bitnami/charts/issues/1210#issuecomment-1145923630
helm upgrade --install postgres bitnami/postgresql \
--set volumePermissions.enabled=true \
--set global.postgresql.auth.postgresPassword=postgres \
--set auth.postgresPassword=postgres \
--set auth.enablePostgresUser=true \
kubectl patch svc postgres-postgresql --type='json' -p '[{"op":"replace","path":"/spec/type","value":"NodePort"}]'
# Install localstack