如何使用 envconsul 在 pod 中设置 ENV 变量

How to set ENV variables in pod using envconsul

我正在尝试使用 envconsul 将环境变量推送到 docker 容器 运行ning openliberty。变量是从保险库中提取的。 Consul、Vault 和 Openliberty 应用程序 pod 在 minikube 上 运行ning。 Pod 还从 configmap 中提取非机密变量。

根据日志,变量已被提取,但当我执行 运行 env 命令时无法在 pod 中查看它们。

此外,configmap 中的变量在服务器启动时不可用,但是一旦 pod 启动,env 命令就会显示它们。

应用程序 docker 文件有 CMD[./startup.sh]。

startup.sh 有这个命令

"/usr/local/bin/envconsul -log-level debug -config "/etc/envconsul/envconsul-config.hcl" /opt/ol/wlp/bin/server run defaultServer"

k 条记录pod/mp

2019/09/11 19:05:38.723258 [INFO] envconsul v0.9.0 (fd1ee3c7)
2019/09/11 19:05:38.723278 [INFO] (runner) creating new runner (once: false)
2019/09/11 19:05:38.723492 [DEBUG] (runner) final config: 9/09/11 19:05:38.723536 [INFO] (runner) creating watcher
2019/09/11 19:05:38.723615 [INFO] looking at vault secret/myapp/config
2019/09/11 19:05:38.724356 [INFO] (runner) starting
2019/09/11 19:05:38.724379 [DEBUG] (watcher) adding vault.read(secret/myapp/config)
2019/09/11 19:05:38.739500 [DEBUG] (runner) receiving dependency vault.read(secret/myapp/config)
2019/09/11 19:05:38.739527 [INFO] (runner) running
2019/09/11 19:05:38.739562 [DEBUG] (runner) setting USERNAME="appuser" from vault.read(secret/myapp/config)
2019/09/11 19:05:38.739659 [INFO] (child) spawning: /opt/ol/wlp/bin/server run defaultServer

Launching defaultServer (Open Liberty 19.0.0.8/wlp-1.0.31.cl190820190813-1136) on Eclipse OpenJ9 VM, version 1.8.0_222-b10 (en_US)

[AUDIT   ] CWWKE0001I: The server defaultServer has been launched.
[AUDIT   ] CWWKG0093A: Processing configuration drop-ins resource: /opt/ol/wlp/usr/servers/defaultServer/configDropins/defaults/keystore.xml
[AUDIT   ] CWWKG0093A: Processing configuration drop-ins resource: /opt/ol/wlp/usr/servers/defaultServer/configDropins/defaults/open-default-port.xml
[WARNING ] CWWKG0011W: The configuration validation did not succeed. Value "${env.DB_MF_PORT}" is not a number.
[WARNING ] CWWKG0083W: A validation failure occurred while processing the [portNumber] property, value = [${env.DB_MF_PORT}]. Default value in use: [50000].
[WARNING ] CWWKG0033W: The value [myKeyStore] specified for the reference attribute [keyStoreRef] was not found in the configuration.
[AUDIT   ] CWWKS4104A: LTPA keys created in 1.419 seconds. LTPA key file: /opt/ol/wlp/output/defaultServer/resources/security/ltpa.keys
[AUDIT   ] CWPKI0803A: SSL certificate created in 2.867 seconds. SSL key file: /opt/ol/wlp/output/defaultServer/resources/security/key.p12
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://mp:9080/ibm/api/
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://mp:9080/metrics/
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://mp:9080/openapi/ui/
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://mp:9080/health/
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://mp:9080/openapi/
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://mp:9080/${app_context_root}/
[AUDIT   ] CWWKZ0001I: Application microprofile started in 13.021 seconds.
[AUDIT   ] CWWKF0012I: The server installed the following features: [appSecurity-2.0, cdi-2.0, distributedMap-1.0, jaxb-2.2, jaxrs-2.1, jaxrsClient-2.1, jaxws-2.2, jdbc-4.2, jndi-1.0, jpa-2.2, jpaContainer-2.2, json-1.0, jsonp-1.1, monitor-1.0, mpConfig-1.3, mpHealth-2.0, mpMetrics-2.0, mpOpenAPI-1.1, mpRestClient-1.3, servlet-4.0, ssl-1.0].
[AUDIT   ] CWWKF0011I: The defaultServer server is ready to run a smarter planet. The defaultServer server started in 23.484 seconds.

我更改了 dockerfile 中的 CMD 和 envconsul 的配置文件,现在可以使用了

CMD ["/usr/local/bin/envconsul", "-log-level","debug", "-config","/etc/envconsul/envconsul-config.hcl"]

配置文件

# This block defines the configuration the the child process to execute and manage.
exec{
  # This is the command to execute as a child process. There can be only one command per process.
  command = "/opt/ol/wlp/bin/server run defaultServer"
  }