Helm中的PostgreSQL:initdbScripts参数 [英] PostgreSQL in Helm: initdbScripts Parameter

查看:140
本文介绍了Helm中的PostgreSQL:initdbScripts参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PostgreSQL的默认Helm Chart(即stable/postgresql)定义了一个initdbScripts参数,该参数允许运行初始化脚本.但是,我似乎无法通过命令行发布正确的格式.

The default Helm Chart for PostgreSQL (i.e. 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.

有人可以提供一个如何填充此命令行参数的示例吗?

这就是我要发布的内容,减去了initdbScripts参数的有效版本.

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

推荐答案

根据稳定/postgresql 掌舵图,initdbScripts是初始化脚本名称的字典,这些脚本是多行变量:

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."

我们假设我们具有以下init.sql脚本:

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;

当我们要将多行文本注入值时,我们需要处理YAML中的缩进.

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 docker TO helm;" \
--set service.type=LoadBalancer

以上示例有一些解释:

  1. 如果脚本名称为.,则应将其转义,例如"init\.sql".
  2. 脚本的内容用双引号引起来,因为它是多行字符串变量.
  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.

这篇关于Helm中的PostgreSQL:initdbScripts参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆