Loki environment variable

Use environment variables in the configuration

Note: This feature is only available in Loki 2.1+.

You can use environment variable references in the configuration file to set values that need to be configurable during deployment. To do this, pass -config.expand-env=true and use:

${VAR}

Where VAR is the name of the environment variable.

Each variable reference is replaced at startup by the value of the environment variable. The replacement is case-sensitive and occurs before the YAML file is parsed. References to undefined variables are replaced by empty strings unless you specify a default value or custom error text.

To specify a default value, use:

${VAR:default_value}

Where default_value is the value to use if the environment variable is undefined.

Pass the -config.expand-env flag at the command line to enable this way of setting configs.

I don’t quite understand what this means, can we use the following configuration to give an example?

storage_config:
boltdb:
directory: /tmp/loki/index

filesystem:
directory: /tmp/loki/chunks

@cf2423707774 sure, see below

2 Likes

Thank you very much for your reply. :grinning:

If I install Loki locally on liunx, what is the corresponding command to start Loki in this example? I tried some of the following commands, but none of them succeeded.

./loki-linux-amd64 -config.file=loki-local-config.yaml  -config.expand-env=true
./loki-linux-amd64 -config.file=loki-local-config.yaml 
./loki-linux-amd64 -config.file=loki-local-config.yaml  -config.expand-env=true CHUNKS_DIR=/tmp/chunks

Can you please provide more detail?
What error message did you get?