简体   繁体   中英

PostgreSQL in Helm: initdbScripts Parameter

The default Helm Chart for PostgreSQL (ie stable/postgresql ) defines an initdbScripts parameter that allows initialization scripts to be run. However, I can't seem to get the format correct on how to issue it via the command line.

Could someone provide an example of how to populate this command line parameter?

Here's what I'm issuing, minus a working version of the initdbScripts parameter.

helm install stable/postgresql -n testpg \
    --set global.postgresql.postgresqlDatabase=testpg \
    --set global.postgresql.postgresqlUsername=testpg \
    --set global.postgresql.postgresqlPassword=testpg \
    --set global.postgresql.servicePort=5432 \
    --set initdbScripts=(WHAT GOES HERE TO RUN "sql/init.sql"??) \
    --set service.type=LoadBalancer

According to stable/postgresql helm chart, initdbScripts is a dictionary of init script names which are multi-line variables:

 ## initdb scripts ## Specify dictionary of scripts to be run at first boot ## Alternatively, you can put your scripts under the files/docker-entrypoint-initdb.d directory ## # initdbScripts: # my_init_script.sh:| # #!/bin/sh # echo "Do something."

Let's assume that we have the following init.sql script:

CREATE USER helm;
CREATE DATABASE helm;
GRANT ALL PRIVILEGES ON DATABASE helm TO helm;

When we are going to inject a multi-line text into values we need to deal with indentation in YAML.

For above particular case it is:

helm install stable/postgresql -n testpg \
--set global.postgresql.postgresqlDatabase=testpg \
--set global.postgresql.postgresqlUsername=testpg \
--set global.postgresql.postgresqlPassword=testpg \
--set global.postgresql.servicePort=5432 \
--set initdbScripts."init\.sql"="CREATE USER helm;
CREATE DATABASE helm;
GRANT ALL PRIVILEGES ON DATABASE helm TO helm;" \
--set service.type=LoadBalancer

There is some explanation to above example:

  1. If script's name has . it should be escaped, like "init\\.sql" .
  2. Script's content is in double quotes, because it's multi-line string variable.

Here's what @nickgryg's answer looks like with values.yaml instead of command line switches.

primary:
  initdb:
    scripts:
      init.sql: |
        CREATE USER helm;
        CREATE DATABASE helm;
        GRANT ALL PRIVILEGES ON DATABASE helm TO helm;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM