how to pass args (i.e.configuration) when deploy on openshift by io.fabric8 ~ fabric8-maven-plugin

2,075 views
Skip to first unread message

Franco Rondini

unread,
Jan 31, 2018, 9:27:42 PM1/31/18
to vert.x
My application, named 'booster-rest-http', is based on io.vertx.vertx-core and io.vertx.vertx-web ver. 3.4.2
My goal is to provide my specific configuration when I execute it.
Running the application locally I got what I want but I can not get the same result when I run it in the openshift deployment.

To get what I want in a local environment I launch:
`java -Drondinif.env = DEV -jar booster-rest-http-1.0.0-SNAPSHOT.jar run org.rondinif.api.vertx.HttpApplication --conf booster-rest-http.json`

I want to deploy on openshift by `f8-m-p`, i.e:` io.fabric8 ~ fabric8-maven-plugin`
With [reference to the manual] (http://maven.fabric8.io/fabric8-maven-plugin.pdf), I am now using it in `openshift mode` mentioned in chapter `1.3. Configuration` as **Zero-Config**.
In this way the application is up and running on openshift but without my specific conf.
I'm not able to understand how specify the configuration parameter that I would like to point to a ConfigMap mounted on pods and available on the pod /config/booster-rest-http.json

I have no experience or examples of previous work from which to get ideas, and even if I tried to read the documentation and try to adopt others configuration styles such as **Kubernetes & OpenShift resource fragments** ( instead of **Zero-Config** ) I have not yet figured out how I can change the way the application is run on the openshift pod.

From what I understand the pod always starts running: `/opt/run-java/run-java.sh` and what I see running is always:
xargs -0 printf '%s\n' </proc/1/cmdline
java
-Dvertx.cacheDirBase=/tmp
-javaagent:/opt/jolokia/jolokia.jar=config=/opt/jolokia/etc/jolokia.properties
-XX:+UseParallelGC
-XX:MinHeapFreeRatio=20
-XX:MaxHeapFreeRatio=40
-XX:GCTimeRatio=4
-XX:AdaptiveSizePolicyWeight=90
-XX:MaxMetaspaceSize=100m
-XX:+ExitOnOutOfMemoryError
-cp
.
-jar
/deployments/booster-rest-http-1.0.0-SNAPSHOT.jar

any help that addresses me in the right direction is appreciated, thanks


Clement Escoffier

unread,
Feb 1, 2018, 3:17:27 AM2/1/18
to ve...@googlegroups.com
Hello,

The Fabric8 Maven Plugin use a “S2I” mechanism (I won’t enter in the details about S2I here, let me know if you need more details).

So, there are several way to configure your application. If you want to pass command line parameter, create a `deployment.yaml` in `src/main/fabric8` with the following content:
spec:
  template:
    spec:
      containers:
        - name: vertx
          env:
            - name: KUBERNETES_NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: JAVA_OPTIONS
              value: '-Dvertx.cacheDirBase=/tmp ….'
            - name: JAVA_ARGS
              value: '-cluster'

JAVA_OPTIONS are arguments passed to the JVM, JAVA_ARGS are arguments passed to the application. (example available here: https://github.com/cescoffier/vertx-kubernetes-workshop/blob/master/compulsive-traders/src/main/fabric8/deployment.yml)

Now, if you want to read a config map mounted as a file, in the same file, use:

spec:
  template:
    spec:
      # Declare a volume mounting the config map
      volumes:
        - configMap:
            # Name of the config map
            name: app-config
            # Define the items from the config map to mount
            items:
            - key: config.json
              path: config.json
            # Volume name (used as reference below)
          name: config
      containers:
        - name: vertx
          env:
            - name: KUBERNETES_NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: JAVA_OPTIONS
              value: '-Dvertx.cacheDirBase=/tmp'
            - name: JAVA_ARGS
              value: ‘-config /deployments/config/config.json'
          # Mount the volume define above in /deployments/config
          volumeMounts:
            - name: config
              mountPath: /deployments/config

There are other ways to configure Vert.x application in Kubernetes / OpenShift. For instance you can use vertx-config to read the config map as in https://github.com/openshiftio-vertx-boosters/vertx-configmap-booster/blob/master/src/main/java/io/openshift/booster/HttpApplication.java. So no need to customize the deployment.yaml.

If you need more details about Vert.x in OpenShift, I recommend this workshop: https://github.com/cescoffier/vertx-kubernetes-workshop

Clement

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/bc99a758-c072-466f-b951-e68a9566f376%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Franco Rondini

unread,
Feb 1, 2018, 10:47:19 AM2/1/18
to vert.x
Hello Clement, thanks to your instructions now it works exactly as I wanted, ...now I begin to understand how ** Kubernetes & OpenShift resource fragments ** works and I consider this a good and useful approach. Thanks  also for the links to the examples that as soon as I can I'll  study for sure!
Regards,
Franco 
Reply all
Reply to author
Forward
0 new messages