![Page 1: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/1.jpg)
Developing Java based microservices
ready for the world of containers
@davsclaus davsclaus
davsclaus.comClaus Ibsen
![Page 2: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/2.jpg)
Claus Ibsen• Principal Software Engineer
at Red Hat
• Apache Camel8 years working with Camel
• Author of Camel in Action books
@davsclaus davsclaus
davsclaus.com
![Page 3: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/3.jpg)
![Page 4: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/4.jpg)
![Page 5: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/5.jpg)
![Page 6: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/6.jpg)
?
![Page 7: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/7.jpg)
?
![Page 8: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/8.jpg)
OS Level Virtualization
Docker Orchestration
PaaS Platform on top of Kubernetes
Services and Tools forKubernetes and OpenShift
![Page 9: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/9.jpg)
Kubernetes
![Page 10: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/10.jpg)
Kubernetes
‣ Open Source orchestration platform for Docker containers
• Rewrite of Google’s internal framework “Borg”‣ Declarative specification of a desired state‣ Self-healing‣ Service discovery‣ Scheduling across hosts‣ Replication
![Page 11: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/11.jpg)
Architecture
![Page 12: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/12.jpg)
Key Concepts‣Nodes• Worker machine (physical or VM) running pods‣Pods
• Collection of one or more Docker containers‣Replication Controller
• Creates and takes care of Pods‣Services
• Network Proxy for a collection of Pods‣Labels
• Grouping and organization of Objects‣Namespaces
• Virtual clusters backend by same physical cluster
![Page 13: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/13.jpg)
Pod
‣ Collection of Docker containers running on the same host.
‣ Pods have unique IPs‣ Containers in a Pod ….
• …. share the same IP address• …. can reach each other via local ports• …. can share data via volumes‣ Pods can have one or more Labels
![Page 14: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/14.jpg)
Replication Controller
‣ Controls Pods selected by Labels‣ Ensures that a specified number of Pod replicas is
running‣ Holds Pod templates for creating new Pods‣ Autoscaling‣ Rolling Updates
![Page 15: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/15.jpg)
Service
‣ View on a set of Pods with single IP address and port
‣ Pods are selected by Label‣ Services are referenced by
environment variables‣ Service addresses stay stable
• Pods come and go (with different IPs)
![Page 16: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/16.jpg)
What is Kubernetes?
http://blog.kubernetes.io/2016/06/illustrated-childrens-guide-to-kubernetes.html
![Page 17: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/17.jpg)
https://fabric8.io/
![Page 18: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/18.jpg)
fabric8
‣ Opinionated microservices platform based on Docker, Kubernetes and Jenkins
• Management: console, logging, metrics, dashboards, …• Continuous Delivery Pipeline• iPaaS: Camel route visualization, API registry, Messaging as
a Service, …• Tools: Kubernetes/OpenShift build integration, Kubernetes
component test support, CDI extensions• Quickstarts: Ready to use examples, also available as
Maven archetypes
![Page 19: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/19.jpg)
Kubernetes Demo Time
![Page 20: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/20.jpg)
Java Developer
?
![Page 21: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/21.jpg)
Build a Camel Demo
Time
![Page 23: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/23.jpg)
Hello Service
Hello ServiceClient
![Page 24: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/24.jpg)
Hello Service
Hello Service
name=Claus
Hi $name I am $HOSTNAME
Client
![Page 25: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/25.jpg)
Implementation
Client Hello Service
HTTP
WildFySwarmSpring Boot WildFly Swarm
![Page 26: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/26.jpg)
Implementation
Hello Service
Client Hello Service
HTTP
![Page 27: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/27.jpg)
Implementation
Client Hello Service
HTTP
from timer to http
logfrom undertow
transform
hello service
![Page 28: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/28.jpg)
Spring Boot Starter
![Page 29: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/29.jpg)
Client
![Page 30: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/30.jpg)
WildFly Swarm Generator
![Page 31: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/31.jpg)
Hello Service
![Page 32: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/32.jpg)
Hello Service
![Page 33: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/33.jpg)
Ready to run local
Client Hello Service
HTTP 8080
from timer to netty
logfrom undertow
transform
hello service
![Page 34: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/34.jpg)
How to build Docker Image?
Maven Project Docker Image
![Page 35: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/35.jpg)
Docker Maven Plugin
Maven Project Fabric8 Maven Plugin Docker Imagebuild
https://maven.fabric8.io
![Page 37: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/37.jpg)
Install fabric8-maven-plugin
mvn io.fabric8:fabric8-maven-plugin:3.1.37:setup
https://maven.fabric8.io
![Page 38: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/38.jpg)
Fabric8 Maven Plugin
![Page 39: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/39.jpg)
Build Docker Imagemvn package fabric8:build
![Page 40: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/40.jpg)
Local Docker RepositoryHello Service
Client
![Page 41: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/41.jpg)
Our Demo
Client Hello Service
HTTP 8080
from timer to http
logfrom undertow
transform
hello service
![Page 42: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/42.jpg)
Static vs Dynamic Platform
Client Hello Service
HTTP 8080
from timer to http
logfrom undertow
transform
hello service
Hardcoded hostname and port
![Page 43: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/43.jpg)
Dynamic Platform
Hello Service
HTTP 8080
Client
from timer to http
logfrom undertow
transform
hello service
Kubernetes Service
![Page 44: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/44.jpg)
Kubernetes Service• Network Connection to one or more Pods
• Unique static IP and port (lifetime of service)
![Page 45: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/45.jpg)
Kubernetes Service
HTTP 8080
from timer to http
logfrom undertow
transform
hello service
kube proxy
Kubernetes Master
enlisted on deployment
changes
pod
node
pod
node
![Page 46: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/46.jpg)
Kubernetes Servicefrom user point of view
service ip:port
from timer to http
logfrom undertow
transform
hello service
pod pod
![Page 47: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/47.jpg)
Out of the box serviceMaven artifactId
WildFly Swarm HTTP port
![Page 48: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/48.jpg)
Custom Configured Service service.yml
Container Port = Inside
Service Port = Outside
Service Name
![Page 49: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/49.jpg)
Using Kubernetes Service
Client
from timer to http
log
We want to use hello service
How do we do that?
![Page 50: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/50.jpg)
Using Kubernetes Service
• Environment Variables
• Hostname
• Port
Client
from timer to http
log
Service Discovery using DNS is available in newer versions of Kubernetes.
![Page 51: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/51.jpg)
Service using ENV• Use ENV Client
from timer to http
log
![Page 52: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/52.jpg)
Service using DNS• Use DNS Client
from timer to http
log
![Page 53: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/53.jpg)
Service using DNSClient
from timer to http
log
Kubernetes Service
![Page 54: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/54.jpg)
Ready to run in Kubernetes
Client Hello Service
{{service:hello}}
from timer to netty
logfrom undertow
transform
hello service
kube proxy
![Page 55: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/55.jpg)
How to deploy to Kubernetes?
Maven Project
![Page 56: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/56.jpg)
How to deploy to Kubernetes?
Maven Project fabric8 Maven Plugin
run
![Page 57: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/57.jpg)
Deploy - Hello Service
Hello Service
from undertow transform
hello service
• mvn fabric8:run
![Page 58: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/58.jpg)
Deploy - Client
• mvn fabric8:run Client
from timer to http
log
![Page 59: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/59.jpg)
Running Kubernetes Locally
• MiniKube
• MiniShift
• Vagrant
• OpenShift CDK
https://fabric8.io/guide/getStarted/index.html
![Page 60: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/60.jpg)
Running fabric8• Download gofabric8 https://github.com/fabric8io/gofabric8/releases
• Start fabric8gofabric8 start --minishift --console --memory=2000
https://fabric8.io/guide/getStarted/minishift.html
![Page 61: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/61.jpg)
fabric8 Web Console
minishift service fabric8
![Page 62: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/62.jpg)
OpenShift CLI• oc get pods
You can also use CLI from docker &
kubernetes
![Page 63: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/63.jpg)
OpenShift CLI• oc get service
![Page 64: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/64.jpg)
OpenShift CLI• oc logs -f <pod name>
![Page 65: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/65.jpg)
• minishift service hello
Access Servicefrom your laptop
![Page 66: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/66.jpg)
Scaling• Change deployment replicas
![Page 67: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/67.jpg)
Scaling• Service load balancing
Load balancing is random
![Page 68: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/68.jpg)
Angry Pods
1st person shooter - Kill your pods
![Page 69: Developing Java based microservices ready for the world of containers](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f9b341760da3da068bd425/html5/thumbnails/69.jpg)
Links• fabric8
• http://fabric8.io • Demo source code
• https://github.com/davsclaus/fabric8-hello • Try kubernetes / fabric8
• https://fabric8.io/guide/getStarted/minishift.html • Videos, blogs and more
• https://fabric8.io/community/index.html
@davsclaus davsclaus
davsclaus.com