如何在 Envoy 中使用环境变量

发布于 2025-01-17 18:05:29 字数 73 浏览 5 评论 0原文

如何指定主机和端口数据而不将其显式写入 yaml 文件中?我想使用环境变量,但到目前为止我所有的尝试都会导致 json 解析器错误。

How can I specify host and port data without writing it explicitly in the yaml file? I'd like to use environment variables, but so far all my attempts result in a json parser error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我鬧 2025-01-24 18:05:29

1

您需要使用EnvSubst的选项,该工具可以帮助您将变量放入Envoy.yaml。您可以在路径TMPL/Envoy.yaml.tmpl的路径中这样做,

cat /tmpl/envoy.yaml.tmpl | envsubst \$ARG_1,\$ARG_2 > /etc/envoy.yaml

我们保存我们的临时配置,在其中使用$ arg_1和$ arg_2的处方。然后,我们将这些变量从.env中取出。因此,我们可以运行的最终配置将在/etc/envoy.yaml中。

如果您想了解有关EnvSubst的更多信息,我建议您阅读以下文章:

2

使用jinja2 + python将您的template.j2文件渲染到yaml。您可以在Google中找到更多有用的信息或阅读本文:

1 Option

You need to use envsubst, a tool that helps you put variables into envoy.yaml. You can do it this way

cat /tmpl/envoy.yaml.tmpl | envsubst \$ARG_1,\$ARG_2 > /etc/envoy.yaml

In the path tmpl/envoy.yaml.tmpl we save our temporary config where we prescribed where $ARG_1 and $ARG_2 will be used. Then we take these variables out of .env and rewrite $ARG_1 and $ARG_2 in the new config to their values. So our final config that we can run will be in /etc/envoy.yaml.

If you would like to learn more about envsubst, I recommend reading the following articles:

2 Option

Also you can use jinja2 + python to render your template.j2 files to yaml. You can find more useful information in Google or read this article:
Generate yaml file with python and jinja2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文