Tomcat-in-the-cloud is the current name of the project that seeks to port Tomcat clustering into cloud services such as Kubernetes and OpenShift.
- Docker
- Kubernetes CLI (to orchestrate from the command line)
Minishift is a light-weight OpenShift platform that is easy to install and quickly up and running. This platform is perfect for testing out new features like Tomcat-in-the-Cloud. To download and install Minishift, refer to the official documentation.
Once Minishift is installed, proceed with the following instructions :
- Start Minishift
$ minishift start
- Set up the docker environment
$ eval $(minishift docker-env)
- Login with a user/password of your choice. We'll use admin/password
$ oc login -u admin -p password
- Create a new project. Again, we will call it tomcat-in-the-cloud but feel free to use the one you'd like
$ oc new-project tomcat-in-the-cloud
- Using Docker, log into the running Openshift docker registry
$ docker login -u $(oc whoami) -p $(oc whoami -t) $(minishift openshift registry)
- If not already done, clone the repository and change directory to get to its root
$ git clone https://github.com/web-servers/tomcat-in-the-cloud.git
$ cd tomcat-in-the-cloud
- Build the docker image providing the war file of the application you would like to deploy (relative path). You also have to specify the registry_id which is the name of your Openshift project
$ docker build --build-arg war=[war_file] --build-arg registry_id=$(oc project -q) . -t $(minishift openshift registry)/$(oc project -q)/image
The name of the project can be retreived using $(oc project -q)
.
- Push the resulting docker image onto the docker registry
$ docker push $(minishift openshift registry)/$(oc project -q)/image
Once built and pushed on the docker registry, we need to run and expose the docker image.
- Allow Openshift pods to see their peers (a must for session replication to work)
$ oc policy add-role-to-user view system:serviceaccount:$(oc project -q):default -n $(oc project -q)
- Run the docker image into one container
$ kubectl run $(oc project -q) --image=$(minishift openshift registry)/$(oc project -q)/image:latest --port 8080
- Expose the deployment on port 80 for it to be accessible
$ kubectl expose deployment $(oc project -q) --type=LoadBalancer --port 80 --target-port 8080
Your clustered application should now be up and running, you can connect to Openshift GUI using $ minishift console
. When done simply log in and manage your application!
Classes in the package org.example.tomcat.cloud.stream
are taken from the
JGroups-Kubernetes
project. This project also served as inspiration for our implementation.