When running applications on a cloud platform (such as Kubernetes) you often need to read config values that the platform supplies.
When running applications on a cloud platform (such as Kubernetes) you often need to read config values that the platform supplies.
It's not uncommon to use environment variables for such purposes, but this can have drawbacks, especially if the value is supposed to be kept secret.
It's not uncommon to use environment variables for such purposes, but this can have drawbacks, especially if the value is supposed to be kept secret.
...
@@ -696,10 +696,10 @@ For example, Kubernetes can volume mount both https://kubernetes.io/docs/tasks/c
...
@@ -696,10 +696,10 @@ For example, Kubernetes can volume mount both https://kubernetes.io/docs/tasks/c
There are two common volume mount patterns that can be use:
There are two common volume mount patterns that can be use:
. A single file contains a complete set of properties (usually written as YAML).
. A single file contains a complete set of properties (usually written as YAML).
. Multiple files are written to a directory with the filename becoming the '`key`' and the contents becoming the '`value`'.
. Multiple files are written to a directory tree, with the filename becoming the '`key`' and the contents becoming the '`value`'.
For the first case, you can import the YAML or Properties file directly using `spring.config.import` as described <<boot-features-external-config-files-importing,above>>.
For the first case, you can import the YAML or Properties file directly using `spring.config.import` as described <<boot-features-external-config-files-importing,above>>.
For the second case, you need to use the `volumemount:` prefix so that Spring Boot knows it needs to expose all the files as properties.
For the second case, you need to use the `configtree:` prefix so that Spring Boot knows it needs to expose all the files as properties.
As an example, let's imagine that Kubernetes has mounted the following volume:
As an example, let's imagine that Kubernetes has mounted the following volume:
...
@@ -718,12 +718,12 @@ To import these properties, you can add the following to your `application.prope
...
@@ -718,12 +718,12 @@ To import these properties, you can add the following to your `application.prope
[source,properties,indent=0]
[source,properties,indent=0]
----
----
spring.config.import=volumemount:/etc/config
spring.config.import=configtree:/etc/config
----
----
You can then access or inject `myapp.username` and `myapp.password` properties from the `Environment` in the usual way.
You can then access or inject `myapp.username` and `myapp.password` properties from the `Environment` in the usual way.
TIP: Volume mounted values can be bound to both string `String` and `byte[]` types depending on the contents expected.
TIP: Configuration tree values can be bound to both string `String` and `byte[]` types depending on the contents expected.