Using fabric8 ToolSet

The fabric8-maven-plugin(https://maven.fabric8.io/) brings your Java applications on to Kubernetes and OpenShift quickly with zero change of your source code and configuration, this section demonstrates use fabric8 plugin to build docker image, create OpenShift resource descriptors and add appication to OpenShift from souce code automaticly.

About Application

The spring-boot-cxf-jaxrs provides a rest layer of vdb-datafederation-swarm which deployed in previous chapter, the completed souce code and document can be find from

The rest api including:

  • /rest/query

  • /rest/query/account/products

  • /rest/query/marketData/stockPrices

  • /rest/query/stocks

Run Application on OpenShift

$ git clone https://github.com/jbosschina/spring-boot-cxf-jaxrs.git
$ cd spring-boot-cxf-jaxrs
$ mvn fabric8:deploy

The above commands will do

  • Add a Build

  • Add a Deployment

The command line takes a little less time, so let’s use that option. First, find the name of the DC:

Diving into the process

oc get build
$ oc get build
NAME                          TYPE      FROM      STATUS     STARTED         DURATION
spring-boot-cxf-jaxrs-s2i-1   Source    Binary    Complete   5 minutes ago   1m20s
oc get pod
$ oc get pod
NAME                                READY     STATUS      RESTARTS   AGE
spring-boot-cxf-jaxrs-1-cg0k1       0/1       Running     0          15s
spring-boot-cxf-jaxrs-1-deploy      1/1       Running     0          18s
spring-boot-cxf-jaxrs-s2i-1-build   0/1       Completed   0          1m
vdb-datafederation-swarm-1-2lknm    1/1       Running     0          2h

After the deploying finished, execute:

oc get pod --show-all=false
$ oc get pod --show-all=false
NAME                               READY     STATUS    RESTARTS   AGE
spring-boot-cxf-jaxrs-1-cg0k1      1/1       Running   0          7m
vdb-datafederation-swarm-1-2lknm   1/1       Running   0          2h
**
$ oc get service
NAME                       CLUSTER-IP       EXTERNAL-IP   PORT(S)     AGE
spring-boot-cxf-jaxrs      172.30.151.123   <none>        80/TCP      7m
vdb-datafederation-swarm   172.30.193.238   <none>        31000/TCP   2h
oc get deploymentconfig
$ oc get deploymentconfig
NAME                       REVISION   DESIRED   CURRENT   TRIGGERED BY
spring-boot-cxf-jaxrs      1          1         1         config,image(spring-boot-cxf-jaxrs:latest)
vdb-datafederation-swarm   1          1         1         config,image(vdb-datafederation-swarm:1.0)

Use Environment Variables to Control VDB Connections

$ oc get dc
NAME                       REVISION   DESIRED   CURRENT   TRIGGERED BY
spring-boot-cxf-jaxrs      7          1         1         config,image(spring-boot-cxf-jaxrs:latest)
vdb-datafederation-swarm   1          1         1         config,image(vdb-datafederation-swarm:1.0)

Then, use the oc env command to set environment variables directly on the DC:

$ oc env dc spring-boot-cxf-jaxrs -e DB_USERNAME=sa -e DB_PASSWORD=sa -e DB_NAME=Portfolio -e DB_HOST=vdb-datafederation-swarm
deploymentconfig "spring-boot-cxf-jaxrs" updated

Creating a Route

A Route will make a service accessable externally. oc expose can simplely create a route:

$ oc expose service spring-boot-cxf-jaxrs
route "spring-boot-cxf-jaxrs" exposed

ALternatively, create https encription route via:

$ oc create route edge spring-boot-cxf-jaxrs --service=spring-boot-cxf-jaxrs
route "spring-boot-cxf-jaxrs" created

Verify the Route was created via:

$ oc get route
NAME                    HOST/PORT                                                               PATH      SERVICES                PORT      TERMINATION   WILDCARD
spring-boot-cxf-jaxrs   spring-boot-cxf-jaxrs-wf-swarm-example.apps.na1.openshift.opentlc.com             spring-boot-cxf-jaxrs   http                    None

results matching ""

    No results matching ""