Search code examples
yamlenvironment-variablesenvoyproxy

How to use enviroment variables in Envoy


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.


Solution

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