Kubernetes:如何从另一个环境变量引用一个环境变量? [英] Kubernetes: How to refer to one environment variable from another?
问题描述
I've a Deployment
object where I expose the POD ID using the Downward API. That works fine. However, I want to set up another env variable, log path, with reference to the POD ID. But, setting that variable value to /var/log/mycompany/${POD_ID}/logs
isn't working, no logs are created in the container.
I can make the entrypoint script or the app aware of the POD ID, and build up the log path, but I'd rather not do that.
推荐答案
The correct syntax is to use $(FOO)
, as is described in the v1.EnvVar value:
documentation; the syntax you have used is "shell" syntax, which isn't the way kubernetes interpolates variables. So:
containers:
- env:
- name: POD_ID
valueFrom: # etc etc
- name: LOG_PATH
value: /var/log/mycompany/$(POD_ID)/logs
还请注意,如文档中所述,必须在引用该变量的变量之前定义要扩展的变量.
Also please note that, as mentioned in the Docs, the variable to expand must be defined before the variable referencing it.
这篇关于Kubernetes:如何从另一个环境变量引用一个环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!