[helm/charts] [bitnami/postgresql] Unable to execute an init DB script on bare metal Kubernetes (#23183)

From: notifications@github.com
Domain: IP info github.com
MX-server: IP info out-27.smtp.github.com
Size: 3821 Bytes
Create: 2020-07-14
Update: 2020-07-14
Score: 0
Safe: Yes

Outbound domains: github.com |

Describe the bug
I'm trying to create several databases after installation. I added setting initdbScripts into helm install command:

helm install postgresql bitnami/postgresql --namespace=namespace_name \
    --set global.postgresql.postgresqlUsername=username,global.postgresql.postgresqlPassword=password123 \
    --set initdbScripts."init\.sql"="CREATE DATABASE db1;
GRANT ALL PRIVILEGES ON DATABASE db1 TO username;
CREATE DATABASE db2;
GRANT ALL PRIVILEGES ON DATABASE db2 TO username;
CREATE DATABASE db3;
GRANT ALL PRIVILEGES ON DATABASE db3 TO username;"

The pod starts failing with CrashLoopBackOff, and there's a line in the log:
touch: cannot touch '/bitnami/postgresql/.user_scripts_initialized': Permission denied

My assumption why it does not work is that I have installed the chart to a bare-metal cluster and since it has no dynamic provisioning set up, I created a volume first:

kind: PersistentVolume
apiVersion: v1
metadata:
  name: postgresql-data
  labels:
    type: local
    app: postgresql
  annotations:
    volume.alpha.kubernetes.io/storage-class: postgresql-data
spec:
  storageClassName: postgresql-data
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle
  hostPath:
    path: "/opt/postgresql-data"

The volume is successfully claimed by PVC which I don't create manually.

Is there a way to initialize several databases using initdbScripts on a BM Kubernetes cluster? Any bare SQL or combined with Bash script solution would work.

Version of Helm and Kubernetes:
helm version:
version.BuildInfo{Version:"v3.0.2", GitCommit:"19e47ee3283ae98139d98460de796c1be1e3975f", GitTreeState:"clean", GoVersion:"go1.13.5"}

kubectl version:

Client Version: version.Info{Major:"1", Minor:"16+", GitVersion:"v1.16.6-beta.0", GitCommit:"e7f962ba86f4ce7033828210ca3556393c377bcc", GitTreeState:"clean", BuildDate:"2020-01-15T08:26:26Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.5", GitCommit:"e6503f8d8f769ace2f338794c914a96fc335df0f", GitTreeState:"clean", BuildDate:"2020-06-26T03:39:24Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}

Which chart:
[bitnami/postgresql]

Anything else we need to know:
My solution is based on the best response in this thread: https://stackoverflow.com/questions/55499984/postgresql-in-helm-initdbscripts-parameter


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Want to protect your real email from messages like this? Use TempM email and be more secure on the internet.