TransitioningToMicroServonDocker_MS
-
Upload
lana-kalashnyk -
Category
Documents
-
view
124 -
download
0
Transcript of TransitioningToMicroServonDocker_MS
1
Transitioning to Java MicroServices on Docker
Lana KalashnykW Consulting Group
Welcome to Houston TechFest
• Please turn off all electronic devices or set them to vibrate.• If you must take a phone call, please do so in the lobby so as not
to disturb others.• Thanks to our Diamond Sponsors:
Thank you for being a part of the 9th Annual Houston TechFest!
3
Transitioning to Java Microservices• Let’s talk about …• Microservices :
– Microservices … what makes them different ?– Microservice Architectures
• What is Docker? – Containers are in . – How to use Docker for microservices.
• Business Application: Outdated Web Services. • Demo of a Java Microservice running in a Docker container,
providing status updates on a Bitcoin Node block height.
4
About MeLana Kalashnyk
•BAAS Computer Science minor Business Administration •AS in Computer Science emphasis on Networking
•Cisco CCNA I-IV, Red Hat JAX-RS, NetSuite, CODE WPF, Oracle Java training
•Houston Java User Group, Houston .Net User Group, Texas DevOps User Group, PuppetConf Test Pilot
•Fan of back end engineering, cloud technologies, innovation and running.
www.wcgp.coTwitter: lana_vk
5
• When did Microservices became a thing?
• Not a new Idea, but a relatively new trend in Software Architectures for smaller companies.
• Mentioned in 2011 Yegge Memo to Google about the way Amazon largely runs their company as microservices communicating exclusively over APIs.
https://plus.google.com/+RipRowan/posts/eVeouesvaVX
The Rise of The Microservices
6
Company culture matters
“Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the
organization's communication structure.” – Melvin Conway, 1967
7
What is a Microservice ?Microservices is a software architecture style in which complex applications are composed of small, independent processes.
– These processes communicate with each other using language-agnostic APIs.
– These services are small, highly decoupled and focus on doing a small task.
– Facilitate a modular approach to system-building.– The service is autonomous; it is full-stack and has control of all
the components – UI, middleware, persistence, transaction.
•“A perfect JavaEE microservice is single ECB component within a WAR deployed on a single server”
8
Benefits of using MicroservicesA Well written Microservice operates on a single
resource. •Allows to focus on building a product rather than a project. (each service is developed independently, not a refactor of a monolith) •Independently deployable.•Smart endpoints. •RESTFUL protocols or Message queues can be used for non-blocking communication. •Doesn’t have to be all in one technology•Infrastructure Automation : making releases boring .•Fault isolation : Helps with fixing the issue, rather than deploying a patch .
9
Pitfalls of using Microservices• Creating so-called Nanoservices . Services that are too
granular, their maintenance and implementation are counterproductive.
• Lack of Tooling. Transitioning to a microservice architecture implies investment into management and monitoring tools. Failure to do so will surely result in a poor system.
• Change Management, Transactions and Data Integrity can be tricky
10
Microservice Architecture Patterns• Aggregate : An aggregator invokes multiple
microservices to achieve desired functionality.
11
Microservice Architecture Patterns• Chained: A single microservice produces a single
consolidated response. Service A invokes Service B… etc
12
Microservice Architecture Patterns• Shared data: Microservices access the same
database.
13
What are containers ?• Containers are a solution to the problem of how to get software to
run reliably when moved from one computing environment to another.
• Put simply, a container consists of an entire runtime environment: an application, plus all its dependencies, libraries and other binaries, and configuration files needed to run it, bundled into one package.
“By containerizing the application platform and its dependencies, differences in OS distributions and underlying infrastructure are abstracted away.” –Paul Rubens CIO
14
Why do we need them?• Immutable Servers – BIG WIN
– Immutable containers mean that they will never be changed. A new version of an application is deployed in a new container
• No More Magical Servers.– You deploy in the environment you build the product for… all the time.
• Isolation. Applications are isolated by the container boundaries.
• Smarter use of resources when compared to separate VMs.
• Continuous Integration and Delivery .
15
What is Docker?
Docker is an open platform for building, shipping and running distributed applications. It gives programmers, development teams and operations engineers the common toolbox they need to take advantage of the distributed and networked nature of modern applications.
Docker consists of:•The Docker Engine - container virtualization technology combined with a work flow for building and containerizing applications.•Docker Hub - SaaS service for sharing and managing your application stacks.
CoreOS rkt is the only other major player in the field.
16
Docker Architecture
17
Deploying Microservices on Docker• Microservice and any necessary software is
“baked” into a Docker Image.• The Image is created based on a Docker file. All
necessary set up is specified here. • Docker Images are stored in Docker Registry• Multi-container applications can be defined using
Docker compose. • Containers can be deployed as a Cluster using
Docker SWARM.
18
Transition from .Net Web Services on IIS • In a recent project we replaced outdated .Net
Web Services running on an IIS Service with Java Microservice deployed on Docker in a Wildfly AS .– Good candidate due to few dependencies. – Already separated by product in separate web services– Needed to drastically cut costs– Low risk project since doesn’t provide critical data
writes– Other applications in the eco system were already Java
based
19
Usage Example: Previous Architecture
20
Usage Example: New Architecture
21
Work in Progress• Committing to a microservice architecture beyond
a small project is a much bigger undertaking.• Define architecture patterns for cross technology
interactions• Define scaling mechanisms • Define state monitoring • Or deploy on AWS or Google to leverage their pre-
built tools
22
And now a working Example !• The following solution imitates the previous
architecture. It consists of :– Virtual Machine : Complex Web Application ( Bitcoin
Node)– Docker Container : Java Microservice polling the
Bitcoin Node– Simple ReactJS Web Page displaying the results.
23
Pre requisites• Install a Bitcoin Node
– I used AWS EC2 t2.medium instance w/ 48 GiB volume.– Configure the Security group to allow traffic to our
node from other bitcoin nodes and our application.
24
Configure the Bitcoin Node• Install the bitcoin node software on your provisioned server. • Configure the node to accept JSON-RPC requests from our IP only.
– sudo vi .bitcoin/bitcoin.conf
• Start the bitcoin daemon. Now you can manage it using bitcoin-cli commands
– sudo bitcoind –daemon– sudo bitcoin-cli getinfo
25
Writing a Java Microservice• Install Maven, Git, NetBeans (or an IDE of your
choice)• Only work on a single resource
– Here a Bitcoin Node • Make the end points RESTFUL (PUT, POST, GET)• Use JSON to package objects. • Report Errors• Log
26
Writing a Java Microservice
27
Writing a Java Microservice
28
Wildfy Swarm• Add Wildfly Swarm Dependency & Plugin
to package the service into a container in your pom file
<dependency> <groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-jaxrs-weld</artifactId>
<version>1.0.0.Alpha5-SNAPSHOT</version></dependency><dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.2</version></dependency>…
<!-- *** Swarm Plugin *** --><!-- Specify the main class in your app --><!-- Executution phase and goal --><plugin> <groupId>org.wildfly.swarm</groupId> <artifactId>wildfly-swarm-plugin</artifactId> <configuration> <mainClass>com.mius.javajaxrsmicroservice.JaxRSServriceSwarmMain</mainClass> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>package</goal> </goals> </execution> </executions> </plugin>
29
Could stop here..• Build the Service and package it into a Swarm
Container – mvn clean package
• Jar file is fully executable… • Execute using
– “java –jar JavaMSDocker-swarm.jar”
• but then we wouldn’t get to talk about Docker.
30
Install Docker• https://docs.docker.com/compose/install/• Depending on your OS you can either run Docker
natively or in a VirtualBox• Docker Toolbox installs Docker Machine and other
tools like Kitematic.
31
Create a Docker File• Create a file name “Dockerfile”
– Specify the base image • FROM java:openjdk-8-jdk
– Copy over your files into the container• ADD target/JavaMSDocker-swarm.jar /opt/JavaMSDocker-
swarm.jar
– Open port 8080 for our Service• EXPOSE 8080
– Configure the container to run as an executable• ENTRYPOINT ["java", "-jar", "/opt/JavaMSDocker-swarm.jar"]
32
Docker Compose• For Development use. Optional.• Define all services to be ran together in a .yml file• Create a file name “docker-compose.yml”
wildflyswarm: // define service name build: . // path to the Dockerfile ports: - "8080:8080" // ports to expose HOST:CONTAINER
33
Create your Docker Image• Run the following commands :
docker-compose builddocker run –p 8080:8080 javamsdocker_wildflyswarmOrdocker-compose up
34
The service is live !
35
React Page to display the data• For simplicity uses simple jquery to GET the
bitcoin node status from the java microservice• Uses virtual DOM• JSX transforms in browser
36
Final Page
37
Referenceshttps://en.wikipedia.org/wiki/Microserviceshttp://blog.arungupta.me/microservices-monoliths-noops/https://www.voxxed.com/blog/2015/04/coupling-versus-autonomy-in-microservices/
http://www.javacodegeeks.com/2015/04/microservice-design-patterns.html
http://www.cio.com/article/2924995/enterprise-software/what-are-containers-and-why-do-you-need-them.html
https://docs.docker.com/introduction/understanding-docker/
http://wildfly.org/swarm/
http://tutorialzine.com/2014/07/5-practical-examples-for-learning-facebooks-react-framework/
http://blog.arungupta.me/deploy-javaee-docker-swarm-cluster/
https://bitcoin.org/en/full-node#ubuntu-1410
38
Pull thisGitHub Repo for the Bitcoin Monitor Demo
https://github.com/lana-vk/JavaMicroServiceDocker
39
Thank You !
Lana KalashnykW Consulting Group
wcgp.coTwitter : @lana_vk
Please Leave Feedback During Q&AIf you leave session feedback and provide contact information in the survey, you will be qualified for a prize
Scan the QR Code to the right or go to http://bit.ly/1K1Hvi5
Thanks to all our Sponsors!