Skip to content

animeshsingh/Java-MicroProfile-on-Kubernetes-20170505173124998

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Deploy MicroProfile based Java microservices on Kubernetes Cluster

This code demonstrates the deployment of a Java based microservices application using MicroProfile and Microservice Builder on Kubernetes Cluster.

MicroProfile is a baseline platform definition that optimizes Enterprise Java for a microservices architecture and delivers application portability across multiple MicroProfile runtimes. Microservice Builder builds on top of MicroProfile.io, and provides extension for containerized apps created using the tool to be deployed to Kubernetes.

The Microservice Builder sample application is a web application for managing a conference and is based on a number of discrete microservices. The front end is written in Angular; the backing microservices are in Java. All run on WebSphere Liberty, in Docker containers managed by Kubernetes.

Flow

Included Components

Prerequisite

Deploy to Kubernetes Cluster from Bluemix

If you want to deploy directly to Bluemix, click on 'Deploy to Bluemix' button below to create a Bluemix DevOps service toolchain and pipeline for deploying the Java microservices using MicroProfile sample, else jump to Steps

Create Toolchain

Please follow the Toolchain instructions to complete your toolchain and pipeline.

Steps

  1. Install Docker CLI and Bluemix Container registry Plugin
  2. Get and build the application code
  3. Build application containers
  4. Create Services and Deployments

1. Install Docker CLI and Bluemix Container Registry Plugin

First, install Docker CLI.

Then, install the Bluemix container registry plugin.

bx plugin install container-registry -r bluemix

Once the plugin is installed you can log into the Bluemix Container Registry.

bx cr login

If this is the first time using the Bluemix Container Registry you must set a namespace which identifies your private Bluemix images registry. It can be between 4 and 30 characters.

bx cr namespace-add <namespace>

Verify that it works.

bx cr images

2. Get and build the application code

Note: For the following steps, you can get the code and build the package by running the get_code.sh script present in scripts directory.

  • git clone the following projects:

       git clone https://github.com/WASdev/sample.microservicebuilder.web-app.git
       git clone https://github.com/WASdev/sample.microservicebuilder.schedule.git
       git clone https://github.com/WASdev/sample.microservicebuilder.speaker.git
       git clone https://github.com/WASdev/sample.microservicebuilder.session.git
       git clone https://github.com/WASdev/sample.microservicebuilder.vote.git
       cd sample.microservicebuilder.vote/
       git checkout 4bd11a9bcdc7f445d7596141a034104938e08b22
  • mvn clean package in each ../sample.microservicebuilder.* projects

3. Build application containers

Use the following commands to build the microservers containers.

Build the web-app microservice container

cd sample.microservicebuilder.web-app
docker build -t registry.ng.bluemix.net/<namespace>/microservice-webapp .
docker push registry.ng.bluemix.net/<namespace>/microservice-webapp

Build the vote microservice container

cd sample.microservicebuilder.vote
docker build -t registry.ng.bluemix.net/<namespace>/microservice-vote .
docker push registry.ng.bluemix.net/<namespace>/microservice-vote

Build the schedule microservice container

cd sample.microservicebuilder.schedule
docker build -t registry.ng.bluemix.net/<namespace>/microservice-schedule .
docker push registry.ng.bluemix.net/<namespace>/microservice-schedule

Build the speaker microservice container

cd sample.microservicebuilder.speaker
docker build -t registry.ng.bluemix.net/<namespace>/microservice-speaker .
docker push registry.ng.bluemix.net/<namespace>/microservice-speaker

Build the session microservice container

cd sample.microservicebuilder.session
docker build -t registry.ng.bluemix.net/<namespace>/microservice-session .
docker push registry.ng.bluemix.net/<namespace>/microservice-session

Build the nginx controller

cd nginx
docker build -t registry.ng.bluemix.net/<namespace>/nginx-server .
docker push registry.ng.bluemix.net/<namespace>/nginx-server

4. Create Services and Deployments

Change the image name given in the respective deployment YAML files for all the projects in the manifests directory with the newly build image names.

Get the public ip of the node

$ kubectl get nodes
NAME             STATUS    AGE
169.47.241.106   Ready     23h

Set the value of SOURCE_IP env variable present in deploy-nginx.yaml file present in manifests folder with the public ip of the node.

Deploy the microservice from the manifests directory with the command kubectl create -f <filename>.

After you have created all the services and deployments, wait for 10 to 15 minutes. You can check the status of your deployment on Kubernetes UI. Run 'kubectl proxy' and go to URL 'http://127.0.0.1:8001/ui' to check when the application containers are ready.

Kubernetes Status Page

After few minutes the following commands to get your public IP and NodePort number.

$ kubectl get nodes
NAME             STATUS    AGE
169.47.241.106   Ready     23h
$ kubectl get svc nginx-svc
NAME        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
nginx-svc   10.10.10.167   <nodes>       80:30056/TCP   11s

Now you can use the link http://[IP]:30056 to access your application on browser.

Web application home page

Web-app Home Page

When you click on speaker name

Speaker Info

When you click on schedules link

Schedule Info

When you click on vote link

Vote Info

Troubleshooting

  • If your microservice instance is not running properly, you may check the logs using
    • kubectl logs <your-pod-name>
  • To delete a microservice
    • kubectl delete -f manifests/<microservice-yaml-file>
  • To delete everything
    • kubectl delete -f manifests

References

License

Apache 2.0