A developer would like to configure an application or the application runtime deployed to Openshift.
This project demonstrates application and runtime configuration leveraging external configuration sources. Alongside the basic means to set up a configmap and use with a specific runtime, this quickstart also demonstrates how changes to the configuration can be applied to services already deployed to openshift.
ConfigMap, Application Configuration, Rollout of changes
To get started with these quickstarts you'll need the following prerequisites:
Name | Description | Version |
---|---|---|
java | Java JDK | 8 |
maven | Apache Maven | 3.2.x |
oc | OpenShift Client | >1.4.1 |
git | Git version management | 2.x |
The project uses WildflySwarm to create and package the service.
Execute the following maven command:
mvn clean install
-
Run the following command to start the maven goal of WildFlySwarm:
mvn wildfly-swarm:run
-
If the application launched without error, use the following command to access the REST endpoint exposed using curl or httpie tool:
http http://localhost:8080/api/greeting curl http://localhost:8080/api/greeting
It should return the value Hello, World!
, which uses the default greeting template due to the lack of a configmap.
But in the next step, running on openshift, we'll supply a configmap with a message
property.
-
Go to OpenShift Online to get the token used by the oc client for authentication and project access.
-
Using the
oc
client, execute the following command to replace MYTOKEN with the one from the Web Console:oc login https://api.dev-preview-int.openshift.com --token=MYTOKEN
-
To allow the WildFly Swarm application running as a pod to access the Kubernetes Api to retrieve the Config Map associated to the application name of the project
swarm-rest-configmap
, the view role must be assigned to the default service account in the current project:oc policy add-role-to-user view -n $(oc project -q) -z default
-
Deploy the configmap to openshift
oc create configmap app-config --from-file=app-config.yml
One you've deployed the configmap, verify it's contents using:
oc get configmap app-config -o yaml
This will return something similar to:
greeting:
message: Hello World!
swarm:
logging: INFO
```
-
Next, use the Fabric8 Maven Plugin to launch the S2I process on the OpenShift Online machine & start the application.
mvn clean fabric8:deploy -Popenshift
-
Get the route url.
oc get route/wildfly-swarm-configmap NAME HOST/PORT PATH SERVICE TERMINATION LABELS wildfly-swarm-configmap <HOST_PORT_ADDRESS> wildfly-swarm-configmap:8080
-
Use the Host or Port address to access the service.
http http://<HOST_PORT_ADDRESS>/api/greeting
Here the response from the REST endpoint should use the greeting template defined in our configmap:
{ "id": 1, "message": "Hello World!" }
-
Update the configuration source that's already deployed to Openshift:
oc edit configmap app-config
Change the value for the
greeting.message
key toBonjour!
and save the file. The changes will be propagated to Openshift. -
Instruct Openshift to rollout a new version of your services to pick up the changes in the configmap:
oc rollout latest dc/wildfly-swarm-configmap
Wait for the pods to become ready:
oc get pods -w
-
Verify that the changes have been picked up by the Wildfly Swarm service implementation:
http http://localhost:8080/api/greeting curl http://localhost:8080/api/greeting
This should return the value you've chosen for the key
greeting.message
, i.e.:{ "id": 1, "message": "Bonjour!" }
Congratulations! You've just finished your first service configuration quickstart.