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

Reactive Java Microservices on Kubernetes with ...

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
Tweet

More Decks by Deepu K Sasidharan

Other Decks in Programming

Transcript

  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 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
  4. @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
  5. @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
  6. @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
  7. @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
  8. @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
  9. @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
  10. @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
  11. @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 :(
  12. @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)
  13. @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
  14. @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