News KrakenD Enterprise v2.6 released with OpenTelemetry, FIPS-140, gRPC server and more

Community Documentation

Recent changes

You are viewing a previous version of KrakenD Community Edition (v1.4) , go to the latest version

Overriding the configuration with environment vars

Document updated on Jul 10, 2020

When KrakenD runs, all the behavior is loaded from the configuration file. Through environment variables you can inject a value in the configuration when the server starts. There are two different ways of injecting environment vars.

First level properties

For each configuration value that isn’t nested (meaning first-level properties of the configuration), you can override its value with an environment variable.

All configuration environment variables that you want to set using environment variables, pass them with a prefix KRAKEND_. The variable name after the prefix must match the property in the configuration value using uppercase.

For instance, take the following krakend.json configuration as an example:

{
    "version": 2,
    "timeout": "3s",
    "name": "Example gateway."
}

To replace values using env vars, run krakend with the following command:

Example: Override configuration with env vars 
$KRAKEND_NAME="Build ABC0123" KRAKEND_TIMEOUT="500ms" krakend run -c krakend.json

The resulting configuration will be:

{
    "version": 2,
    "timeout": "500ms",
    "name": "Build ABC0123"
}

NOTE: The configuration file is not changed. The values above are a representation of the final mapped values.

Overriding properties in any nesting level

If you need to replace content using environment variables at any level, you have to use the flexible configuration. It includes a series of advanced functions including an env function that can write in the config any value.

{ “version”: 2, “name”: “Configuration for {{ env “MY_POD_NAMESPACE” }}” }

Scarf

Unresolved issues?

The documentation is only a piece of the help you can get! Whether you are looking for Open Source or Enterprise support, see more support channels that can help you.