$30 off During Our Annual Pro Sale. View Details »

Kubernetes Native Java with Spring Boot (DevCon 2022)

Kubernetes Native Java with Spring Boot (DevCon 2022)

The Spring ecosystem provides you with all you need to build cloud-native applications, focusing on productivity, simplicity, and speed. It’s ready to leverage cloud environment features and integrates with Kubernetes natively.

In this session, Thomas will cover common patterns and best practices to build cloud-native applications with Java using the reactive programming paradigm in Spring Framework 6, which provides better performance, resilience, and efficiency. You’ll then see how to containerize them with Cloud Native Buildpacks, configure them through the natively supported ConfigMaps and Secrets, and deploy them to a Kubernetes cluster with Knative.

Finally, he’ll show how to use the new capabilities in Spring Boot 3 to build native executables on GraalVM and achieve applications with almost instant startup time and reduced memory consumption, perfect for serverless architectures.

Thomas Vitale

November 09, 2022

More Decks by Thomas Vitale

Other Decks in Technology


  1. Thomas Vitale DevCon Nov 9th, 2022 Kubernetes Native Java With

    Spring Boot @vitalethomas
  2. Systematic • Software Architect at Systematic, Denmark. • Author of

    “Cloud Native Spring in Action” (Manning). • OSS contributor (Java, Spring, Cloud Native Technologies) Thomas Vitale thomasvitale.com @vitalethomas
  3. Cloud Native @vitalethomas

  4. Why Cloud Native? Speed Faster and fl exible delivery Cost

    Ef fi ciency and cost optimisation Scale Elasticity and dynamic scaling Resilience Availability and stability @vitalethomas
  5. From Development to Production A Cloud Native Journey Spring Boot

    Development Cloud Native Buildpacks Containerization Kubernetes Deployment @vitalethomas
  6. Cloud Native Development @vitalethomas

  7. Cloud Native Development Development principles with Spring Boot • Self-contained

    application • Embedded server • No external dependencies • JAR packaging (“uber-JAR”) • Externalized con fi guration • Property fi les for default values • JVM system variables • Environment variables @vitalethomas
  8. Packaging Spring Boot Standalone JAR JAR Gradle bootJar Maven spring-boot:repackage

  9. Containerization @vitalethomas

  10. Image pack build Cloud Native Buildpacks From source code to

    container image @vitalethomas
  11. Packaging Spring Boot JAR & Container Image JAR Container Image

    Gradle bootJar Maven spring-boot:repackage Gradle bootBuildImage Maven spring-boot:build-image @vitalethomas
  12. Spring Boot on Kubernetes @vitalethomas

  13. Knative Serverless experience on Kubernetes @vitalethomas

  14. Serverless Architectures Developers focus on code Focus on business logic

    Developer Platform Infrastructure Provisioning Workload Management Dynamic Scaling @vitalethomas
  15. Knative Serving Serverless Experience on Kubernetes Developer-friendly abstractions From image

    to URL Autoscaling Scaling to zero Progressive Rollouts Request-driven Event-driven Cloud agnostic @vitalethomas
  16. Configuring Resources CPU & Memory CPU Memory When limit hit

    Throttle Compressible Resource When limit hit OOMKilled Non Compressible Resource @vitalethomas
  17. Liveness and Readiness Probes Application ALIVE? READY? NO NO Restart

    might help. Restart won’t help. Don’t send any tra ffi c until it’s ready. @vitalethomas
  18. Health Probes Liveness and readiness • Spring Boot • Use

    Spring Boot Actuator • Liveness and readiness health endpoints are automatically exposed when Kubernetes is detected. • Kubernetes • Con fi gure liveness probe • Con fi gure readiness probe @vitalethomas
  19. Liveness and Readiness Probes When not available, Kubernetes will restart

    the container When not ready, Kubernetes will not send any tra ff i c to the container @vitalethomas
  20. Externalised Configuration @vitalethomas

  21. Code, Configuration, Credentials Code Con fi guration Deploy Credentials @vitalethomas

  22. Configuration Options Spring Boot Properties ‣Property fi les ‣Command line

    arguments ‣Environment variables Con fi guration Services ‣Spring Cloud Con fi g Server ‣Spring Cloud Consul Con fi g ‣Spring Cloud Vault ‣Spring Cloud Zookeeper Con fi g Cloud Platform Services ‣Spring Cloud Alibaba ‣Spring Cloud AWS ‣Spring Cloud Azure ‣Spring Cloud GCP Kubernetes Platform ‣Con fi gMaps ‣Secrets ‣Environment variables @vitalethomas
  23. ConfigMaps & Secrets Mount the volume to the /config path,

    where Spring Boot will automatically read property fi les. Load the Con fi gMap In a volume @vitalethomas
  24. Graceful shutdown Spring Boot and Kubernetes • Spring Boot •

    Enable graceful shutdown • De fi ne a grace period • Kubernetes • Add pre-stop hook • De fi ne a grace period @vitalethomas
  25. Native Images @vitalethomas

  26. Spring Boot 3 Native executables with GraalVM Slower Heavier Build

    Instant Startup Reduced Memory Consumption Instant Peak Performance Fewer Runtime Optimizations @vitalethomas
  27. Resources @vitalethomas

  28. Resources Source code • Presentation source code • Developer experience

    with Java on Kubernetes • Docker fi les vs. Cloud Native Buildpacks • Knative and Spring: Bringing back the func @vitalethomas
  29. https://github.com/ThomasVitale/awesome-spring

  30. Discount codes Manning • 35% discount code, valid for all

    products in all format • ctwdevcon22 • manning.com @vitalethomas
  31. Thomas Vitale DevCon Nov 9th, 2022 Kubernetes Native Java With

    Spring Boot @vitalethomas @thomasvitale@mastodon.online