Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reactive Java Microservices on Kubernetes with Spring and JHipster

Reactive Java Microservices on Kubernetes with Spring and JHipster

Learn how to build Reactive Java microservices easily with Spring WebFlux, Spring Cloud, and JHipster and deploy it to the cloud using Kubernetes. Reactive support in JHipster using Spring WebFlux lets you build powerful reactive applications and microservices easily in a few minutes using JHipster DSL. Spring Cloud makes other aspects of the microservices, like, routing, circuit breaking, etc a breeze. In this session, we will build a reactive microservices application and deploy it to production on the cloud using Kubernetes.

Deepu K Sasidharan

June 10, 2022

More Decks by Deepu K Sasidharan

Other Decks in Programming


  1. @deepu105 @oktaDev Reactive Java Microservices on Kubernetes with Spring and

    JHipster Deepu K Sasidharan @deepu105 | deepu.tech
  2. @deepu105 @oktaDev Hi, I’m Deepu K Sasidharan JHipster co-lead developer

    Java Champion Creator of KDash, JDL Studio Developer Advocate @ Okta OSS aficionado, author, speaker, polyglot dev @deepu105 deepu.tech deepu105
  3. @deepu105 @oktaDev What is reactive programming?

  4. @deepu105 @oktaDev Programming using async data streams (sequence of events

    ordered in time)
  5. @deepu105 @oktaDev Reactive pros and cons • Simple to compose

    data streams • Highly interactive • Avoid callbacks • Ideal for large data size • Complex to learn and implement • Memory intensive • Hard to debug • Not as mature as imperative
  6. @deepu105 @oktaDev Options for Java • Java Flow API ◦

    Introduced in java 9 ◦ Provides interfaces and a simple implementation • Reactive Extensions (RxJava) ◦ Popularly known as ReactiveX ◦ Provide API for async programming with observable streams ◦ Available for multiple programming languages and platforms • Project Reactor ◦ Based on the reactive streams specification ◦ Targeted towards building non-applications on the JVM ◦ Foundation of the reactive stack in the Spring ecosystem
  7. @deepu105 @oktaDev Spring Boot for Reactive

  8. @deepu105 @oktaDev

  9. @deepu105 @oktaDev Spring MVC vs Spring WebFlux

  10. @deepu105 @oktaDev Spring MVC controller code

  11. @deepu105 @oktaDev Spring WebFlux controller code

  12. @deepu105 @oktaDev Do you always need reactive programming?

  13. @deepu105 @oktaDev JHipster

  14. @deepu105 @oktaDev JHipster in a nutshell • Most popular Rapid

    Application Development platform for Java • Scaffold modern web applications, api applications and microservices • Scaffold CRUD entities, CI/CD, Kubernetes, Docker and so on • 19k+ stars, 40k projects and 600+ contributors on GitHub • 2M+ installations & 20k+ app generations per month • Available as Yeoman based Node.js CLI and as an online web application ◦ npm install -g generator-jhipster ◦ Or, start.jhipster.tech
  15. @deepu105 @oktaDev Why JHipster? • Developer experience oriented • Production

    grade code quality (Look at the sonar scores) ◦ • Best practices on the combinations selected • Fully working CRUD apps out of the box • Production grade security • You would only have to do business logic code and UX design
  16. @deepu105 @oktaDev JHipster microservice architecture

  17. @deepu105 @oktaDev Architecture

  18. @deepu105 @oktaDev Spring Cloud Gateway

  19. @deepu105 @oktaDev Spring Cloud Gateway + OIDC

  20. @deepu105 @oktaDev Do you need microservices?

  21. @deepu105 @oktaDev Demo time

  22. @deepu105 @oktaDev Prerequisite - Cluster Create GCP Project : $

    gcloud projects create jhipster-demo - Enable billing $ gcloud config set project jhipster-demo $ gcloud services enable container.googleapis.com Create GKE Cluster : $ gcloud container clusters create hello-hipster \ --num-nodes 4 \ --machine-type n1-standard-2 Set Credentials: $ gcloud container clusters get-credentials hello-hipster
  23. @deepu105 @oktaDev JDL JHipster Domain Language JDL : https://bit.ly/ms-reactive $

    jhipster download microservice-ecommerce-reactive Reference : https://www.jhipster.tech/jdl/ Studio : https://start.jhipster.tech/jdl-studio/ Samples : https://github.com/jhipster/jdl-samples
  24. @deepu105 @oktaDev JHipster magic $ jhipster jdl microservice-ecommerce-reactive --fork

  25. @deepu105 @oktaDev Build & Push images $ ./gradlew bootJar -Pprod

    jib -Djib.to.image=deepu105/store $ ./gradlew bootJar -Pprod jib -Djib.to.image=deepu105/invoice $ ./gradlew bootJar -Pprod jib -Djib.to.image=deepu105/product $ ./gradlew bootJar -Pprod jib -Djib.to.image=deepu105/notification
  26. @deepu105 @oktaDev Okta OIDC integration • Install Okta CLI from

    cli.okta.com • If you don't have an Okta developer account, run okta register else run okta login • cd store && okta apps create jhipster Accept default values • Update kubernetes/registry-k8s/jhipster-registry.yml to add oauth2 profile to SPRING_PROFILES_ACTIVE env variable • Update kubernetes/registry-k8s/application-configmap.yml
  27. @deepu105 @oktaDev Okta OIDC integration data: application.yml: |- ... spring:

    security: oauth2: client: provider: oidc: issuer-uri: https://<your-okta-domain>/oauth2/default registration: Oidc: client-id: <client-id> client-secret: <client-secret> # plaintext secret :(
  28. @deepu105 @oktaDev Deploy to GKE $ cd kubernetes $ ./kubectl-apply.sh

    -f $ watch kubectl get pods -n jhipster \ or use KDash 😉 (brew install kdash-rs/kdash/kdash)
  29. @deepu105 @oktaDev Encrypt secrets • Generate an encrypt key ->

    uuid | base64 • Update kubernetes/registry-k8s/jhipster-registry.yml to add a secret and ENCRYPT_KEY environment variable • ./kubectl-apply.sh -f • kubectl port-forward svc/jhipster-registry -n jhipster 8761 • Update kubernetes/registry-k8s/application-configmap.yml
  30. @deepu105 @oktaDev JHipster Registry

  31. @deepu105 @oktaDev Store Gateway

  32. @deepu105 @oktaDev Additional resources • https://developer.okta.com/blog/2021/06/01/kubernetes-spring-boot-jhipster • https://developer.okta.com/blog/2020/05/04/spring-vault • https://www.youtube.com/watch?v=zGpnIhRgMaM

    • https://developer.okta.com/blog/2022/06/09/cloud-native-java-microservices- with-istio
  33. @deepu105 @oktaDev Main website https://jhipster.tech JHipster online https://start.jhipster.tech GitHub https://github.com/jhipster/generator-jhipster

    Twitter https://twitter.com/java_hipster Stack Overflow https://stackoverflow.com/questions/tagged/jhipster?sort=newest More information on JHipster
  34. @deepu105 @oktaDev Thank You Deepu K Sasidharan @deepu105 | deepu.tech