Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Developing Java based microservices ready for the world of containers

1,507 views

Published on

The so-called experts are saying microservices and containers will
change the way we build, maintain, operate, and integrate
applications. This talk is intended for Java developers who wants to hear and see how you can develop Java microservices that are ready to run in containers.

In this talk we will build a set of Java based Microservices that uses a mix of technologies with Apache Camel, Spring Boot and WildFly Swarm.

You will see how we can build small discrete microservices with these Java technologies and build and deploy on the Kubernets container platform.

We will discuss practices how to build distributed and fault tolerant microservices using technologies such as Kubernetes Services, Camel EIPs, and Netflixx Hysterix.

And the self healing and fault tolerant aspects of the Kubernetes platform is also discussed and demoed when we let the chaos monkeys loose killing containers.

This talk is a 50/50 mix between slides and demo.

The talk was presented at JDKIO on September 13th 2016.

Published in: Internet

Developing Java based microservices ready for the world of containers

  1. 1. Developing Java based microservices ready for the world of containers @davsclaus davsclaus davsclaus.com Claus Ibsen
  2. 2. Claus Ibsen • Principal Software Engineer
 at Red Hat • Apache Camel
 8 years working with Camel • Author of
 Camel in Action books @davsclaus davsclaus davsclaus.com
  3. 3. ?
  4. 4. ?
  5. 5. OS Level Virtualization Docker Orchestration PaaS Platform on top of Kubernetes Services and Tools for Kubernetes and OpenShift
  6. 6. Kubernetes
  7. 7. 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
  8. 8. Architecture
  9. 9. 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
  10. 10. 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
  11. 11. 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
  12. 12. 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)
  13. 13. What is Kubernetes? http://blog.kubernetes.io/2016/06/illustrated-childrens-guide- to-kubernetes.html
  14. 14. https://fabric8.io/
  15. 15. 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
  16. 16. Kubernetes Demo Time
  17. 17. Java Developer ?
  18. 18. Build a Camel Demo Time
  19. 19. Source Code https://github.com/davsclaus/fabric8-hello
  20. 20. Hello Service Hello Service Client
  21. 21. Hello Service Hello Service name=Claus Hi $name I am $HOSTNAME Client
  22. 22. Implementation Client Hello Service HTTP WildFy
 Swarm Spring Boot WildFly Swarm
  23. 23. Implementation Hello Service Client Hello Service HTTP
  24. 24. Implementation Client Hello Service HTTP from timer to http log from undertow transform helloservice
  25. 25. Spring Boot Starter
  26. 26. Client
  27. 27. WildFly Swarm Generator
  28. 28. Hello Service
  29. 29. Hello Service
  30. 30. Ready to run local Client Hello Service HTTP 8080 from timer to netty log from undertow transform helloservice
  31. 31. How to build Docker Image? Maven Project Docker Image
  32. 32. Docker Maven Plugin Maven Project Fabric8 Maven Plugin Docker Image build https://maven.fabric8.io
  33. 33. Fabric8 Maven Plugin https://maven.fabric8.io
  34. 34. Install fabric8-maven-plugin mvn io.fabric8:fabric8-maven-plugin:3.1.37:setup https://maven.fabric8.io
  35. 35. Fabric8 Maven Plugin
  36. 36. Build Docker Image mvn package fabric8:build
  37. 37. Local Docker Repository Hello Service Client
  38. 38. Our Demo Client Hello Service HTTP 8080 from timer to http log from undertow transform helloservice
  39. 39. Static vs Dynamic Platform Client Hello Service HTTP 8080 from timer to http log from undertow transform helloservice Hardcoded hostname and port
  40. 40. Dynamic Platform Hello Service HTTP 8080 Client from timer to http log from undertow transform helloservice Kubernetes Service
  41. 41. Kubernetes Service • Network Connection to one or more Pods • Unique static IP and port (lifetime of service)
  42. 42. Kubernetes
 Service HTTP 8080 from timer to http log from undertow transform helloservice kubeproxy Kubernetes Master enlisted on deployment changes pod node pod node
  43. 43. Kubernetes Service
 from user point of view service ip:port from timer to http log from undertow transform helloservice pod pod
  44. 44. Out of the box service Maven artifactId WildFly Swarm HTTP port
  45. 45. Custom Configured Service service.yml Container Port = Inside Service Port = Outside Service Name
  46. 46. Using Kubernetes Service Client from timer to http log We want to use hello service How do we do that?
  47. 47. Using Kubernetes Service • Environment Variables • Hostname • Port Client from timer to http log Service Discovery using DNS is available in newer versions of Kubernetes.
  48. 48. Service using ENV • Use ENV Client from timer to http log
  49. 49. Service using DNS • Use DNS Client from timer to http log
  50. 50. Service using DNS Client from timer to http log Kubernetes Service
  51. 51. Ready to run in Kubernetes Client Hello Service {{service:hello}} from timer to netty log from undertow transform helloservice kubeproxy
  52. 52. How to deploy to Kubernetes? Maven Project
  53. 53. How to deploy to Kubernetes? Maven Project fabric8 Maven Plugin run
  54. 54. Deploy - Hello Service Hello Service from undertow transform helloservice • mvn fabric8:run
  55. 55. Deploy - Client • mvn fabric8:run Client from timer to http log
  56. 56. Running Kubernetes Locally • MiniKube • MiniShift • Vagrant • OpenShift CDK https://fabric8.io/guide/getStarted/index.html
  57. 57. Running fabric8 • Download gofabric8
 
 https://github.com/fabric8io/gofabric8/releases • Start fabric8
 
 gofabric8 start --minishift --console --memory=2000 https://fabric8.io/guide/getStarted/minishift.html
  58. 58. fabric8 Web Console minishift service fabric8
  59. 59. OpenShift CLI • oc get pods You can also use CLI from docker & kubernetes
  60. 60. OpenShift CLI • oc get service
  61. 61. OpenShift CLI • oc logs -f <pod name>
  62. 62. • minishift service hello Access Service
 from your laptop
  63. 63. Scaling • Change deployment replicas
  64. 64. Scaling • Service load balancing Load balancing is random
  65. 65. Angry Pods 1st person shooter - Kill your pods
  66. 66. 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

×