Skip to content

Latest commit

 

History

History
84 lines (57 loc) · 2.94 KB

config.adoc

File metadata and controls

84 lines (57 loc) · 2.94 KB

Use case: Configuring your application

hola microservice uses DeltaSpike Configuration to obtain the phrase that is displayed.

DeltaSpike allows the configuration to come from different ConfigSources (System properties, Environment variables, JNDI value, Properties file values). The microservices needs a configuration value called "hello" to display the provided value. If no value is informed, the default value (Hola de %s) is used.

We will use 2 different approaches to configure "hola" microservice:

Environment variables

Update the DeploymentConfig:

$ oc set env dc/hola hello="Hola de Env var"

# To unset the env var
$ oc set env dc/hola hello-

ConfigMaps

As you’ve seen, the definition of environment variables causes the DeploymentConfig to recreate the pods with that value set. OpenShift 3.2 allows the use of ConfigMaps

Create a ConfigMap from an existing file:

$ cd hola/
$ oc create configmap translation --from-file=translation.properties
$ oc get configmap translation -o yaml

Mount a volume from ConfigMap

Here we are creating a mounted volume in all pods that reads the file.

$ oc patch dc/hola -p '{"spec":{"template":{"spec":{"containers":[{"name":"hola","volumeMounts":[{"name":"config-volume","mountPath":"/etc/config"}]}],"volumes":[{"name":"config-volume","configMap":{"name":"translation"}}]}}}}'

Update the microservice to read the file

The POD needs a Java System Property to inform the location of the file.

$ oc set env dc/hola JAVA_OPTIONS="-Dconf=/etc/config/translation.properties"

After the deployment, check that the config is present

$ oc get pods -l app=hola
$ oc rsh hola-?-?????
sh-4.2$ cat /etc/config/translation.properties
sh-4.2$ exit

Update the ConfigMap and wait the POD to get updated.

$ oc edit configmap translation
Note
The synchronization between the ConfigMap and the mounted volume takes some time to be performed