Read this in other languages: 한국어.
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 provides means to develop, test and deploy your microservices using a Java and MicroProfile based programming model and tools.
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.
- Kubernetes Cluster
- MicroProfile
- Microservice Builder
- Bluemix DevOps Toolchain Service
- Bluemix Container Service
- Create a Kubernetes cluster. Options include:
- Minikube for local testing
- IBM Bluemix Container Service to deploy in cloud, or
- IBM Cloud Private for either senario. For deploying on Minikube follow the instructions here. For deploying on IBM Cloud Private follow the instructions here
- The code in this particular repository is regularly tested against Kubernetes Cluster from Bluemix Container Service using Travis.
- Install a Git client to obtain the sample code.
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
Please follow the Toolchain instructions to complete your toolchain and pipeline.
- Install Microservice Builder add-ons
- Get and build the application code
- Build application containers
- Create Services and Deployments
First, clone our repository.
git clone https://github.com/IBM/Java-MicroProfile-on-Kubernetes.git cd Java-MicroProfile-on-Kubernetes
Then, install the 2 add-ons, Microservice Builder Fabric and ELK Sample, to collect metrics from the MicroProfile Conference application.
Install Helm and use Helm to install the necessary add-ons on your Kubernetes.
helm init #Install Fabric helm repo add mb http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/microservicebuilder/helm/ helm install --name fabric mb/fabric #Install ELK Sample helm repo add mb-sample https://wasdev.github.io/sample.microservicebuilder.helm.elk/charts helm install --name sample-elk mb-sample/sample-elk
It will take up to 20 minutes to install the Microservice Builder Add-ons on your Kubernetes Cluster. In the meantime, let's start building our applications and microservices.
Note: If you don't want to build your own application, you can use our default Docker images and move on to step 4.
- Install Maven and a Java 8 JDK.
Note: For the following steps, you can get the code and build the packages by running
./scripts/get_code.sh
-
git clone
andmvn clean package
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
-
mvn clean package
in each ../sample.microservicebuilder.* projects
Install Docker CLI and a Docker engine.
Use the following commands to build and push your microservice containers.
Note: For the following steps, you can build and push the images by running
./scripts/build_and_push_docker_images.sh <docker_namespace>
Build the web-app microservice container
docker build -t <docker_namespace>/microservice-webapp sample.microservicebuilder.web-app docker push <docker_namespace>/microservice-webapp
Build the vote microservice container
docker build -t <docker_namespace>/microservice-vote sample.microservicebuilder.vote docker push <docker_namespace>/microservice-vote-cloudant
Build the schedule microservice container
docker build -t <docker_namespace>/microservice-schedule sample.microservicebuilder.schedule docker push <docker_namespace>/microservice-schedule
Build the speaker microservice container
docker build -t <docker_namespace>/microservice-speaker sample.microservicebuilder.speaker docker push <docker_namespace>/microservice-speaker
Build the session microservice container
docker build -t <docker_namespace>/microservice-session sample.microservicebuilder.session docker push <docker_namespace>/microservice-session
Build the nginx controller
docker build -t <docker_namespace>/nginx-server nginx docker push <docker_namespace>/nginx-server
Get the IP of the node
$ kubectl get nodes NAME STATUS AGE 10.76.193.96 Ready 23h
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. Then, set the value of SOURCE_IP
env variable present in deploy-nginx.yaml file present in manifests folder with the IP of the node.
Alternatively, you can run the following script to change the image name and SOURCE_IP for all your YAML files.
If you want to use our default images, use journeycode as the docker_username when you run the script.
./scripts/change_image_name_osx.sh <docker_username> #For Mac users ./scripts/change_image_name_linux.sh <docker_username> #For Linux users
Before you start deploying your application, make sure the Microservice Builder Add-ons are installed and running.
$ kubectl get pods --show-all=true NAME READY STATUS RESTARTS AGE fabric-zipkin-4284087195-d6s1t 1/1 Running 0 11m key-retrieval-deploy-gkr9n 0/1 Completed 0 11m # Make sure this job is completed kibana-dashboard-deploy-rd0q5 1/1 Running 0 11m sample-elk-sample-elk-461262821-rp1rl 3/3 Running 0 11m secret-generator-deploy-bj1jj 0/1 Completed 0 11m # Make sure this job is completed
Now, deploy the microservice with the command kubectl create -f manifests
.
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.
After few minutes the following commands to get your public IP and NodePort number.
$ bx cs workers <cluster_name> OK ID Public IP Private IP Machine Type State Status kube-hou02-pa817264f1244245d38c4de72fffd527ca-w1 184.173.1.55 10.76.193.96 free normal Ready $ kubectl get svc nginx-svc NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE nginx-svc 10.76.193.96 <nodes> 80:30056/TCP 11s
Now you can use the link http://[Public IP]:30056 to access your application on browser and use http://[Public IP]:30500 to access your Kibana for tracking the metrics.
Web application home page
When you click on speaker name
When you click on schedules link
When you click on vote link
Kibana discover page
- 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 all microservices
kubectl delete -f manifests
- To delete Microservice Builder add-ons
helm delete --purge sample-elk
helm delete --purge fabric
- This java microservices example is based on Kubernete's Microprofile Showcase Application.