SlideShare une entreprise Scribd logo
1  sur  45
Télécharger pour lire hors ligne
BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENEVA
HAMBURG COPENHAGEN LAUSANNE MUNICH STUTTGART VIENNA ZURICH
Microservices in Java
Anwendungsentwicklung mit K8S/Openshift
Anatole Tresch, Principal Consultant
@atsticks
About me...
Open Source Enthusiast
JCP Expert Group Member
Apache PPMC Member
Consultant, Trainer, Software Architect
Oracle Star Spec Lead
Contact: anatole.tresch@trivadis.com
Blog: http://maketechsimple.wordpress.com
Slideshare: http://www.slideshare.net/anatoletresch
Twitter: @atsticks
Agenda
• Microservices
• Run in Docker
• Deploying into Kubernetes
• Fabric8
• DevOps and Advanced Topics
Microservices
Microservices
• Single Concerns Principle based on bounded contexts
• Independently deployable
• Isolated
• Clear, minimal API, typically REST
• Development Platforms in Java:
• Java EE
• Microprofile
• OSGI
• Vertx
• Akka
• Dropwizard
• …
Microservices - Build
Build Tools:
• Maven
• Gradle
Created Artifacts:
• jar, war, ear, rar etc.
• Java EE server RT configuration
Our Focus:
• Maven
• Single Jar Deployment
Example Application
https://github.com/atsticks/openshift-workshop/tree/master/spring-boot-CRUD-admin-step1
• Spring Boot Application
• Bootstrap/AngularJS UI
• REST API
• MongoDB Backend
• Standard Maven Build
Starting the Application
1. start a mongodb at @localhost, e.g.
docker run --name mongo -p 27017:27017 -d mongo mongod
2. run mvn clean package spring-boot:run
3. Point your browser at http://localhost:8090/index.html
Run our app as a Docker Container
Run the App as a Docker Container
 See: https://github.com/atsticks/openshift-workshop/tree/master/spring-boot-CRUD-admin-step2
 No changes in your Java Project or Maven
 Write a Dockerfile
 Use Docker to build a local Docker image
 Start DB and APP in Docker
Run the app as a Docker container
Add Dockerfile to application project dir:
Build and run the db and the app as containers:
docker run --name mongo -p 27017:27017 -d mongo mongod
mvn clean package
docker build -t step2 .
docker run -p 8090:8090 --link mongo:mongo -it --name myapp
Challenges
• We have to learn to write Docker files
• Testing the application requires manual action (starting Mongo-DB)
• DB and APP must be linked explicitly.
• Deployment is a separate and manual process
• Separate for the Java App and the Mongo DB
• Different for different stages.
But what we really want is…
• A deployment and packaging technique
• A stable and reliable runtime that
• Supports monitoring and restart components
• Provides easy service location
• Provides automatic fail-over
Container Orchestration
+
Unified Deployment
Possible Container Orchestration Targets today
• Amazon ECS
• Azure Container Service (ACS)
• Cloud Foundry’s Diego
• CoreOS Fleet
• Docker Swarm
• Google Container Engine
• Kubernetes / Openshift
• Mesosphere Marathon
• Cloud Native Computing Foundation (CNCF) recently selected Google’s
Kubernetes container orchestration tool as its first containerization technology.
• Docker also will support Kubernetes OOTB.
Deploy our app into Kubernetes
Deploying into Kubernetes
• Kubernetes requires container images for
• The mongo DB (available in Dockerhub)
• The app container (available in a private Docker registry)
• For each of them we require
• A deployment defining
• The container image to use
• The Number of replicas
• Volume mounts
• Environment and Config
• A service making a deployment accessible
Deploying into Kubernetes
Deployment Descriptors
Service Descriptors
Configuration Descriptor
Still there is one thing missing…
We need a (local)
Kubernetes/Openshift
Cluster
Still there is one pice missing…
Local Kubernetes/Openshift
• Minishift (https://github.com/minishift/minishift )
minishift start --cpus 2 --memory 6000 --vm-driver=virtualbox
$ minishift start
Starting local OpenShift cluster using 'kvm' hypervisor...
...
OpenShift server started.
The server is accessible via web console at:
https://192.168.99.100:8443
You are logged in as:
User: developer
Password: developer
To login as administrator:
oc login -u system:admin
Manually deploying into Kubernetes
1. Setup Openshift/Kubernetes/Docker environment
2. Create mongodb service : oc create -f kube/mongoservice.yml
3. Start mongodb deployment: oc create -f kube/mongodeployment.yml
4. Deploy config map : oc create -f kube/configmap.yml
5. Create app service: oc create -f kube/service.yml
6. Build the project: mvn clean package
7. Build the docker image: docker build -t step3 .
8. Tag the built docker image: docker tag step3 $(minishift openshift
registry)/myproject/step3
9. Push the built image: docker push $(minishift openshift
registry)/myproject/step3
10. Create app deployment: oc create -f kube/deployment.yml
11. get $NODEPORT : oc export svc step3 | grep nodePort
12. Verify service: http://$(minishift ip):$NODEPORT/index.html
Cool, that was
easy…!
Fabric8
• Integrated Development Platform for Kubernetes
• Targeting the creation of cloud native applications and microservices
• Build, test and deploy
• Continuous Delivery pipelines
• Run and manage
• Continuous Improvement and ChatOps
The parts of Fabric8
• Developer Console: web app to create, edit, build, deploy and test Microservices
• Continuous Integration and Continous Delivery: Jenkins Workflows
• Application Management:
• Logging and Metrics, ChatOps and Chaos Monkey
• Integration of Hawtio and Jolokia
• Integration Platform As A Service:
• Visualisation of your Apache Camel integration services
• API Registry
• Messaging As A Service (ActiveMQ)
• Java Tools helps the Java community take full advantage of Kubernetes:
• Maven Plugin
• Junit Kubernetes Support based on Arquillian
• Java Libraries and support for working with Kubernetes
The Fabric8
Maven Plugin
The Fabric8 Maven Plugin
 Brings Java apps on to K8S and Openshift.
 Leverages existing maven config.
 Builds Docker images and K8S/Openshift manifests.
 Supports different levels of customization
 Integrates also the Fabric8 Docker Plugin
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>${latest.version}</version>
</plugin>
The Fabric8 Maven Plugin Goals
Build Goals
 fabric8:build
 fabric8:resource
 fabric8:apply
 fabric8:resource-apply
 fabric8:push
 fabric8:helm
 fabric8:distro
 fabric8:app-catalog
 Development goals
 fabric8:run
 fabric8:deploy
 fabric8:undeploy
 fabric8:start
 fabric8:stop
 fabric8:log
 fabric8:debug
 fabric8:watch
The Fabric8 Maven Plugin Configuration Options
• Zero-Config (using defaults)
• Maven XML configuration (image, deployment)
• External Kubernetes/Openshift resource fragments
• External Dockerfiles
F8MP: Zero-Config Example
1) Setting up dependencies and plugins.
2) Enables a simple embedded Tomcat.
3) Responsible for packaging the application.
4) Generation of a Docker image and
Kubernetes / OpenShift descriptors.
To build the Docker image:
mvn package fabric8:build
To deploy to a cluster:
mvn fabric8:resource fabric8:deploy
See https://maven.fabric8.io/#generator-spring-boot
F8MP: Zero-Config Example
What happened:
 As base image fabric8/java-jboss-openjdk8-jdk is chosen
 enables Jolokia, jmx_exporter.
 sophisticated startup script.
 Creates resource objects:
 Kubernetes Deployment
 Kubernetes Service
 Exports port
 8080 as the application service port
 8778 for Jolokia
 9779 for jmx_exporter access
F8MP: XML Configuration Example
• Docker
• <images> define the Docker images to build
→ Similar for Fabric8 Docker Plugin, except <run> and <external> (ignored)
• <resource> define the resource descriptors for OpenShift or Kuberneres.
• <generator> configures generators.
• <enricher> configured enrichers.
<configuration>…</configuration>
F8MP: XML Configuration Example
1) Standard docker-maven-plugin
configuration for building one
single Docker image
F8MP: XML Configuration Example
2) Kubernetes / OpenShift
resources to create
3) Labels applied globally to all
resource objects
1) Deployment Definition
2) Container to include in the
deployment
3) Container alias to correlate
image with the image definition
in the <images> section. Can
be omitted if only a single
image is used
4) Volume definitions used in the
ReplicaSet
5) One or more Service
definitions.
F8MP: Configuration with external resources
 External resource descriptors (YAML/JSON)
 in the src/main/fabric8 and
src/main/docker
 Each resource gets ist own file, which
contains some skeleton of a resource
description.
 The plugin will pick up the resource, enriches
it and then combines all to a single
kubernetes.yml and openshift.yml.
 Allows free use of any Kubernetes feature.
 Supports resource filtering.
src/main/fabric8/deployment.xml:
Run the App with the Fabric8 Plugin
 See: https://github.com/atsticks/openshift-workshop/tree/master/spring-boot-CRUD-admin-step5
 Mongo DB deployment has been added to the kube folder
 Start DB and APP in Kubernetes/Openshift:
1. oc login -u developer -p developer
2. mvn clean install fabric8:deploy
3. Evaluate the $ROUTE-URL: minishift openshift service list -n myproject
4. Open $ROUTE-URL/index.html in your browser
Packaging
38
More Details:
https://docs.openshift.com/enterprise/3.0/architecture/core_concepts/builds_and_image_streams.html
https://github.com/openshift/source-to-image
Openshift: Source to Image (S2I)
Source
Build
S2I build image Image Stream
Deployment
Pod
Container
Replication Controller
All customizable with Jenkins pipelines!
Helm
• https://helm.sh = Package Manager for Kubernetes
• The latest version of Helm is maintained by the CNCF - in collaboration
with Microsoft, Google, Bitnami and the Helm contributor community.
• With Helm you can
• Package your complete apps into Helm Charts
• Manage Charts in a repository
• Install Charts on CLI or with the helm UI (monocular)
• Update and Rollback installations
• Audit your installations
40
Kubernetes Templates
 https://docs.openshift.org/latest/dev_guide/templates.html
 Templates can contain any number of Kubernetes Descriptors
 Descriptors can be parametrized
 Templates can be used with the CLI as well
as the Web Console
Recap
Recap
 Moving from Java to Kubernetes/Openshift is easy!
 Fabric 8 allows to gradually move along your available skills.
 Minishift/Minikube provide an easy to use/setup local environment.
 S2I/Templates gives you powerful DevOps Support.
 Helm provides a package format applications including dependencies.
Topics not covered
 How to modernize your monoliths.
 How to establish a DevOps culture.
 How to test microservice based applications.
 Operating microservice based applications:
 Tracing, Monitoring, Log Collection, Alerting
 Application and Service Security.
 Data Persistence options in a microservice based architecture.
 Legacy Integration, Hybrid Clouds, Scaling, Data Security etc.
Microservices in Java
@atsticks maketechsimple.wordpress.com
anatole.tresch@trivadis.com
Anatole Tresch
Principal Consultant

Contenu connexe

Tendances

Tendances (20)

Security Patterns for Microservice Architectures - ADTMag Microservices & API...
Security Patterns for Microservice Architectures - ADTMag Microservices & API...Security Patterns for Microservice Architectures - ADTMag Microservices & API...
Security Patterns for Microservice Architectures - ADTMag Microservices & API...
 
Introduction to Microservices
Introduction  to MicroservicesIntroduction  to Microservices
Introduction to Microservices
 
Microservices architecture overview v3
Microservices architecture overview v3Microservices architecture overview v3
Microservices architecture overview v3
 
Unleash the True Power of Spring Cloud: Learn How to Customize Spring Cloud
Unleash the True Power of Spring Cloud: Learn How to Customize Spring CloudUnleash the True Power of Spring Cloud: Learn How to Customize Spring Cloud
Unleash the True Power of Spring Cloud: Learn How to Customize Spring Cloud
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
 
Architecture: Microservices
Architecture: MicroservicesArchitecture: Microservices
Architecture: Microservices
 
Spring to Image
Spring to ImageSpring to Image
Spring to Image
 
Microservices
MicroservicesMicroservices
Microservices
 
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20....Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
 
Microservices - Event-driven & the hidden landmines
Microservices - Event-driven & the hidden landminesMicroservices - Event-driven & the hidden landmines
Microservices - Event-driven & the hidden landmines
 
2020-02-10 Java on Azure Solution Briefing
2020-02-10 Java on Azure Solution Briefing2020-02-10 Java on Azure Solution Briefing
2020-02-10 Java on Azure Solution Briefing
 
Microservices Technology Stack
Microservices Technology StackMicroservices Technology Stack
Microservices Technology Stack
 
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
 
Microservice Architecture JavaCro 2015
Microservice Architecture JavaCro 2015Microservice Architecture JavaCro 2015
Microservice Architecture JavaCro 2015
 
Simplify Cloud Applications using Spring Cloud
Simplify Cloud Applications using Spring CloudSimplify Cloud Applications using Spring Cloud
Simplify Cloud Applications using Spring Cloud
 
Building a High-Performance Reactive Microservices Architecture
Building a High-Performance Reactive Microservices ArchitectureBuilding a High-Performance Reactive Microservices Architecture
Building a High-Performance Reactive Microservices Architecture
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
 
Microservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudMicroservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloud
 
Microservice Architecture Patterns, by Richard Langlois P. Eng.
Microservice Architecture Patterns, by Richard Langlois P. Eng.Microservice Architecture Patterns, by Richard Langlois P. Eng.
Microservice Architecture Patterns, by Richard Langlois P. Eng.
 
What’s New in Spring Data MongoDB
What’s New in Spring Data MongoDBWhat’s New in Spring Data MongoDB
What’s New in Spring Data MongoDB
 

Similaire à Microservices in Java

Kubernetes @ meetic
Kubernetes @ meeticKubernetes @ meetic
Kubernetes @ meetic
Sébastien Le Gall
 

Similaire à Microservices in Java (20)

Build containerized application using Docker and Azure.pdf
Build containerized application using Docker and Azure.pdfBuild containerized application using Docker and Azure.pdf
Build containerized application using Docker and Azure.pdf
 
Rome .NET Conference 2024 - Remote Conference
Rome .NET Conference 2024  - Remote ConferenceRome .NET Conference 2024  - Remote Conference
Rome .NET Conference 2024 - Remote Conference
 
Docker dev ops for cd meetup 12-14
Docker dev ops for cd meetup 12-14Docker dev ops for cd meetup 12-14
Docker dev ops for cd meetup 12-14
 
Overview of Docker
Overview of DockerOverview of Docker
Overview of Docker
 
Dev opsec dockerimage_patch_n_lifecyclemanagement_
Dev opsec dockerimage_patch_n_lifecyclemanagement_Dev opsec dockerimage_patch_n_lifecyclemanagement_
Dev opsec dockerimage_patch_n_lifecyclemanagement_
 
What's New in Docker - February 2017
What's New in Docker - February 2017What's New in Docker - February 2017
What's New in Docker - February 2017
 
Dockerization of Azure Platform
Dockerization of Azure PlatformDockerization of Azure Platform
Dockerization of Azure Platform
 
Get you Java application ready for Kubernetes !
Get you Java application ready for Kubernetes !Get you Java application ready for Kubernetes !
Get you Java application ready for Kubernetes !
 
Container on azure
Container on azureContainer on azure
Container on azure
 
Kubernetes Java Operator
Kubernetes Java OperatorKubernetes Java Operator
Kubernetes Java Operator
 
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
04_Azure Kubernetes Service: Basic Practices for Developers_GAB201904_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
 
Kubernetes for Java Developers
Kubernetes for Java DevelopersKubernetes for Java Developers
Kubernetes for Java Developers
 
Kubernetes @ meetic
Kubernetes @ meeticKubernetes @ meetic
Kubernetes @ meetic
 
Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015
 
Docker
DockerDocker
Docker
 
給 RD 的 Kubernetes 初體驗
給 RD 的 Kubernetes 初體驗給 RD 的 Kubernetes 初體驗
給 RD 的 Kubernetes 初體驗
 
Microservices and containers for the unitiated
Microservices and containers for the unitiatedMicroservices and containers for the unitiated
Microservices and containers for the unitiated
 
Introduction to Containers & Diving a little deeper into the benefits of Con...
 Introduction to Containers & Diving a little deeper into the benefits of Con... Introduction to Containers & Diving a little deeper into the benefits of Con...
Introduction to Containers & Diving a little deeper into the benefits of Con...
 
Introduction to Docker - Vellore Institute of Technology
Introduction to Docker - Vellore Institute of TechnologyIntroduction to Docker - Vellore Institute of Technology
Introduction to Docker - Vellore Institute of Technology
 
Cloud foundry integration-with-openstack-and-docker-bangalorecf-meetup
Cloud foundry integration-with-openstack-and-docker-bangalorecf-meetupCloud foundry integration-with-openstack-and-docker-bangalorecf-meetup
Cloud foundry integration-with-openstack-and-docker-bangalorecf-meetup
 

Plus de Anatole Tresch

Plus de Anatole Tresch (20)

Jsr382: Konfiguration in Java
Jsr382: Konfiguration in JavaJsr382: Konfiguration in Java
Jsr382: Konfiguration in Java
 
Wie man Applikationen nicht bauen sollte...
Wie man Applikationen nicht bauen sollte...Wie man Applikationen nicht bauen sollte...
Wie man Applikationen nicht bauen sollte...
 
The Gib Five - Modern IT Architecture
The Gib Five - Modern IT ArchitectureThe Gib Five - Modern IT Architecture
The Gib Five - Modern IT Architecture
 
The Big Five - IT Architektur Heute
The Big Five - IT Architektur HeuteThe Big Five - IT Architektur Heute
The Big Five - IT Architektur Heute
 
Disruption is Change is Future
Disruption is Change is FutureDisruption is Change is Future
Disruption is Change is Future
 
Configuration with Microprofile and Apache Tamaya
Configuration with Microprofile and Apache TamayaConfiguration with Microprofile and Apache Tamaya
Configuration with Microprofile and Apache Tamaya
 
Configuration beyond Java EE 8
Configuration beyond Java EE 8Configuration beyond Java EE 8
Configuration beyond Java EE 8
 
Alles Docker oder Was ?
Alles Docker oder Was ?Alles Docker oder Was ?
Alles Docker oder Was ?
 
Going Resilient...
Going Resilient...Going Resilient...
Going Resilient...
 
Configure once, run everywhere 2016
Configure once, run everywhere 2016Configure once, run everywhere 2016
Configure once, run everywhere 2016
 
Configuration with Apache Tamaya
Configuration with Apache TamayaConfiguration with Apache Tamaya
Configuration with Apache Tamaya
 
Wie Monolithen für die Zukuft trimmen
Wie Monolithen für die Zukuft trimmenWie Monolithen für die Zukuft trimmen
Wie Monolithen für die Zukuft trimmen
 
Configure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaConfigure Your Projects with Apache Tamaya
Configure Your Projects with Apache Tamaya
 
JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...
 
Legacy Renewal of Central Framework in the Enterprise
Legacy Renewal of Central Framework in the EnterpriseLegacy Renewal of Central Framework in the Enterprise
Legacy Renewal of Central Framework in the Enterprise
 
Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...
Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...
Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...
 
A first Draft to Java Configuration
A first Draft to Java ConfigurationA first Draft to Java Configuration
A first Draft to Java Configuration
 
JSR 354 LJC-Hackday
JSR 354 LJC-HackdayJSR 354 LJC-Hackday
JSR 354 LJC-Hackday
 
Adopt JSR 354
Adopt JSR 354Adopt JSR 354
Adopt JSR 354
 
Go for the Money - JSR 354
Go for the Money - JSR 354Go for the Money - JSR 354
Go for the Money - JSR 354
 

Dernier

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Dernier (20)

WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 

Microservices in Java

  • 1. BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENEVA HAMBURG COPENHAGEN LAUSANNE MUNICH STUTTGART VIENNA ZURICH Microservices in Java Anwendungsentwicklung mit K8S/Openshift Anatole Tresch, Principal Consultant @atsticks
  • 2. About me... Open Source Enthusiast JCP Expert Group Member Apache PPMC Member Consultant, Trainer, Software Architect Oracle Star Spec Lead Contact: anatole.tresch@trivadis.com Blog: http://maketechsimple.wordpress.com Slideshare: http://www.slideshare.net/anatoletresch Twitter: @atsticks
  • 3. Agenda • Microservices • Run in Docker • Deploying into Kubernetes • Fabric8 • DevOps and Advanced Topics
  • 5. Microservices • Single Concerns Principle based on bounded contexts • Independently deployable • Isolated • Clear, minimal API, typically REST • Development Platforms in Java: • Java EE • Microprofile • OSGI • Vertx • Akka • Dropwizard • …
  • 6. Microservices - Build Build Tools: • Maven • Gradle Created Artifacts: • jar, war, ear, rar etc. • Java EE server RT configuration Our Focus: • Maven • Single Jar Deployment
  • 7. Example Application https://github.com/atsticks/openshift-workshop/tree/master/spring-boot-CRUD-admin-step1 • Spring Boot Application • Bootstrap/AngularJS UI • REST API • MongoDB Backend • Standard Maven Build
  • 8. Starting the Application 1. start a mongodb at @localhost, e.g. docker run --name mongo -p 27017:27017 -d mongo mongod 2. run mvn clean package spring-boot:run 3. Point your browser at http://localhost:8090/index.html
  • 9. Run our app as a Docker Container
  • 10. Run the App as a Docker Container  See: https://github.com/atsticks/openshift-workshop/tree/master/spring-boot-CRUD-admin-step2  No changes in your Java Project or Maven  Write a Dockerfile  Use Docker to build a local Docker image  Start DB and APP in Docker
  • 11. Run the app as a Docker container Add Dockerfile to application project dir: Build and run the db and the app as containers: docker run --name mongo -p 27017:27017 -d mongo mongod mvn clean package docker build -t step2 . docker run -p 8090:8090 --link mongo:mongo -it --name myapp
  • 12. Challenges • We have to learn to write Docker files • Testing the application requires manual action (starting Mongo-DB) • DB and APP must be linked explicitly. • Deployment is a separate and manual process • Separate for the Java App and the Mongo DB • Different for different stages.
  • 13. But what we really want is… • A deployment and packaging technique • A stable and reliable runtime that • Supports monitoring and restart components • Provides easy service location • Provides automatic fail-over Container Orchestration + Unified Deployment
  • 14. Possible Container Orchestration Targets today • Amazon ECS • Azure Container Service (ACS) • Cloud Foundry’s Diego • CoreOS Fleet • Docker Swarm • Google Container Engine • Kubernetes / Openshift • Mesosphere Marathon • Cloud Native Computing Foundation (CNCF) recently selected Google’s Kubernetes container orchestration tool as its first containerization technology. • Docker also will support Kubernetes OOTB.
  • 15. Deploy our app into Kubernetes
  • 16. Deploying into Kubernetes • Kubernetes requires container images for • The mongo DB (available in Dockerhub) • The app container (available in a private Docker registry) • For each of them we require • A deployment defining • The container image to use • The Number of replicas • Volume mounts • Environment and Config • A service making a deployment accessible
  • 17. Deploying into Kubernetes Deployment Descriptors Service Descriptors Configuration Descriptor
  • 18. Still there is one thing missing…
  • 19. We need a (local) Kubernetes/Openshift Cluster Still there is one pice missing…
  • 20. Local Kubernetes/Openshift • Minishift (https://github.com/minishift/minishift ) minishift start --cpus 2 --memory 6000 --vm-driver=virtualbox $ minishift start Starting local OpenShift cluster using 'kvm' hypervisor... ... OpenShift server started. The server is accessible via web console at: https://192.168.99.100:8443 You are logged in as: User: developer Password: developer To login as administrator: oc login -u system:admin
  • 21.
  • 22. Manually deploying into Kubernetes 1. Setup Openshift/Kubernetes/Docker environment 2. Create mongodb service : oc create -f kube/mongoservice.yml 3. Start mongodb deployment: oc create -f kube/mongodeployment.yml 4. Deploy config map : oc create -f kube/configmap.yml 5. Create app service: oc create -f kube/service.yml 6. Build the project: mvn clean package 7. Build the docker image: docker build -t step3 . 8. Tag the built docker image: docker tag step3 $(minishift openshift registry)/myproject/step3 9. Push the built image: docker push $(minishift openshift registry)/myproject/step3 10. Create app deployment: oc create -f kube/deployment.yml 11. get $NODEPORT : oc export svc step3 | grep nodePort 12. Verify service: http://$(minishift ip):$NODEPORT/index.html
  • 24.
  • 25. Fabric8 • Integrated Development Platform for Kubernetes • Targeting the creation of cloud native applications and microservices • Build, test and deploy • Continuous Delivery pipelines • Run and manage • Continuous Improvement and ChatOps
  • 26. The parts of Fabric8 • Developer Console: web app to create, edit, build, deploy and test Microservices • Continuous Integration and Continous Delivery: Jenkins Workflows • Application Management: • Logging and Metrics, ChatOps and Chaos Monkey • Integration of Hawtio and Jolokia • Integration Platform As A Service: • Visualisation of your Apache Camel integration services • API Registry • Messaging As A Service (ActiveMQ) • Java Tools helps the Java community take full advantage of Kubernetes: • Maven Plugin • Junit Kubernetes Support based on Arquillian • Java Libraries and support for working with Kubernetes
  • 28. The Fabric8 Maven Plugin  Brings Java apps on to K8S and Openshift.  Leverages existing maven config.  Builds Docker images and K8S/Openshift manifests.  Supports different levels of customization  Integrates also the Fabric8 Docker Plugin <plugin> <groupId>io.fabric8</groupId> <artifactId>fabric8-maven-plugin</artifactId> <version>${latest.version}</version> </plugin>
  • 29. The Fabric8 Maven Plugin Goals Build Goals  fabric8:build  fabric8:resource  fabric8:apply  fabric8:resource-apply  fabric8:push  fabric8:helm  fabric8:distro  fabric8:app-catalog  Development goals  fabric8:run  fabric8:deploy  fabric8:undeploy  fabric8:start  fabric8:stop  fabric8:log  fabric8:debug  fabric8:watch
  • 30. The Fabric8 Maven Plugin Configuration Options • Zero-Config (using defaults) • Maven XML configuration (image, deployment) • External Kubernetes/Openshift resource fragments • External Dockerfiles
  • 31. F8MP: Zero-Config Example 1) Setting up dependencies and plugins. 2) Enables a simple embedded Tomcat. 3) Responsible for packaging the application. 4) Generation of a Docker image and Kubernetes / OpenShift descriptors. To build the Docker image: mvn package fabric8:build To deploy to a cluster: mvn fabric8:resource fabric8:deploy
  • 32. See https://maven.fabric8.io/#generator-spring-boot F8MP: Zero-Config Example What happened:  As base image fabric8/java-jboss-openjdk8-jdk is chosen  enables Jolokia, jmx_exporter.  sophisticated startup script.  Creates resource objects:  Kubernetes Deployment  Kubernetes Service  Exports port  8080 as the application service port  8778 for Jolokia  9779 for jmx_exporter access
  • 33. F8MP: XML Configuration Example • Docker • <images> define the Docker images to build → Similar for Fabric8 Docker Plugin, except <run> and <external> (ignored) • <resource> define the resource descriptors for OpenShift or Kuberneres. • <generator> configures generators. • <enricher> configured enrichers. <configuration>…</configuration>
  • 34. F8MP: XML Configuration Example 1) Standard docker-maven-plugin configuration for building one single Docker image
  • 35. F8MP: XML Configuration Example 2) Kubernetes / OpenShift resources to create 3) Labels applied globally to all resource objects 1) Deployment Definition 2) Container to include in the deployment 3) Container alias to correlate image with the image definition in the <images> section. Can be omitted if only a single image is used 4) Volume definitions used in the ReplicaSet 5) One or more Service definitions.
  • 36. F8MP: Configuration with external resources  External resource descriptors (YAML/JSON)  in the src/main/fabric8 and src/main/docker  Each resource gets ist own file, which contains some skeleton of a resource description.  The plugin will pick up the resource, enriches it and then combines all to a single kubernetes.yml and openshift.yml.  Allows free use of any Kubernetes feature.  Supports resource filtering. src/main/fabric8/deployment.xml:
  • 37. Run the App with the Fabric8 Plugin  See: https://github.com/atsticks/openshift-workshop/tree/master/spring-boot-CRUD-admin-step5  Mongo DB deployment has been added to the kube folder  Start DB and APP in Kubernetes/Openshift: 1. oc login -u developer -p developer 2. mvn clean install fabric8:deploy 3. Evaluate the $ROUTE-URL: minishift openshift service list -n myproject 4. Open $ROUTE-URL/index.html in your browser
  • 39. More Details: https://docs.openshift.com/enterprise/3.0/architecture/core_concepts/builds_and_image_streams.html https://github.com/openshift/source-to-image Openshift: Source to Image (S2I) Source Build S2I build image Image Stream Deployment Pod Container Replication Controller All customizable with Jenkins pipelines!
  • 40. Helm • https://helm.sh = Package Manager for Kubernetes • The latest version of Helm is maintained by the CNCF - in collaboration with Microsoft, Google, Bitnami and the Helm contributor community. • With Helm you can • Package your complete apps into Helm Charts • Manage Charts in a repository • Install Charts on CLI or with the helm UI (monocular) • Update and Rollback installations • Audit your installations 40
  • 41. Kubernetes Templates  https://docs.openshift.org/latest/dev_guide/templates.html  Templates can contain any number of Kubernetes Descriptors  Descriptors can be parametrized  Templates can be used with the CLI as well as the Web Console
  • 42. Recap
  • 43. Recap  Moving from Java to Kubernetes/Openshift is easy!  Fabric 8 allows to gradually move along your available skills.  Minishift/Minikube provide an easy to use/setup local environment.  S2I/Templates gives you powerful DevOps Support.  Helm provides a package format applications including dependencies.
  • 44. Topics not covered  How to modernize your monoliths.  How to establish a DevOps culture.  How to test microservice based applications.  Operating microservice based applications:  Tracing, Monitoring, Log Collection, Alerting  Application and Service Security.  Data Persistence options in a microservice based architecture.  Legacy Integration, Hybrid Clouds, Scaling, Data Security etc.
  • 45. Microservices in Java @atsticks maketechsimple.wordpress.com anatole.tresch@trivadis.com Anatole Tresch Principal Consultant