Deploy on OpenShift


Install the following:


There are multiple flavors of oc and OpenShift. This guide was tested with:

$ oc version

oc v3.10.45
kubernetes v1.10.0+b81c8f8
features: Basic-Auth

openshift v3.10.45
kubernetes v1.10.0+b81c8f8

This guide uses as an example, you will have to use your own OpenShift cluster and your docker image registry or a local minishift instance.


First, let’s prepare a few environment variables to make things easier:

## obtain the token at the Console UI on you Openshift server
export TOKEN=<my-token>
## The registry should be accessible from the cluster where you deploy

## Use a project name that will not clash with other deployments on the cluster
export OPENSHIFT_PROJECT=play-java-grpc-example
export IMAGE=play-java-grpc-example
export TAG=1.0-SNAPSHOT

Login to OpenShift from your terminal and create the OpenShift project:

oc login https://$OPENSHIFT_SERVER --token=$TOKEN
oc new-project $OPENSHIFT_PROJECT

Create the docker image of your application and push it to the image registry.

sbt docker:publishLocal

docker login -p $TOKEN -u unused $DOCKER_REGISTRY_SERVER

## The `kustomize` step uses a `kustomization.yml` prepared for $DOCKER_REGISTRY/$IMAGE:$TAG.
## You will have to create your own `deployment/overlays` folder (make a copy of
## `deployment/overlays/my-openshift-cluster` and edit `kustomization.yml`).
kustomize build deployment/overlays/my-openshift-cluster | oc apply -f -

and verify the deployment completed successfully:

$ oc get all 
NAME                                                         READY     STATUS    RESTARTS   AGE
pod/play-java-grpc-example-v1-0-snapshot-5b77bd9849-69wws   1/1       Running   0          16h
pod/play-java-grpc-example-v1-0-snapshot-5b77bd9849-9p657   1/1       Running   0          16h

NAME                              TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)             AGE
service/play-java-grpc-example   ClusterIP   <none>        9000/TCP,9443/TCP   17h

NAME                                                    DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/play-java-grpc-example-v1-0-snapshot   2         2         2            2           17h

NAME                                                               DESIRED   CURRENT   READY     AGE
replicaset.apps/play-java-grpc-example-v1-0-snapshot-5b77bd9849   2         2         2         16h

NAME                                                     DOCKER REPO                                                                                         TAGS           UPDATED   1.0-SNAPSHOT   17 hours ago

NAME                                             HOST/PORT               PATH      SERVICES                  PORT      TERMINATION   WILDCARD             play-java-grpc-example   http                    None

Test the application:

$ curl -H "Host:" \
Hello, Caplin!