简体   繁体   English

Helm 中的 PostgreSQL:initdbScripts 参数

[英]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. PostgreSQL(即stable/postgresql )的默认 Helm Chart 定义了一个initdbScripts参数,允许运行初始化脚本。 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.这是我发布的内容,减去initdbScripts参数的工作版本。

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:根据stable/postgresql helm chart, initdbScripts是 init 脚本名称的字典,它是多行变量:

 ## 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:假设我们有以下init.sql脚本:

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.当我们要将多行文本注入到值中时,我们需要处理 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" .它应该被转义,比如"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.这是 @nickgryg 使用values.yaml而不是命令行开关的答案。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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