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

Kubernetes Native Java with Spring Boot (DevCon 2022)

Thomas Vitale
November 09, 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
Tweet

More Decks by Thomas Vitale

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. From Development to Production A Cloud Native Journey Spring Boot

    Development Cloud Native Buildpacks Containerization Kubernetes Deployment @vitalethomas
  4. 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
  5. Packaging Spring Boot JAR & Container Image JAR Container Image

    Gradle bootJar Maven spring-boot:repackage Gradle bootBuildImage Maven spring-boot:build-image @vitalethomas
  6. Serverless Architectures Developers focus on code Focus on business logic

    Developer Platform Infrastructure Provisioning Workload Management Dynamic Scaling @vitalethomas
  7. 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
  8. Configuring Resources CPU & Memory CPU Memory When limit hit

    Throttle Compressible Resource When limit hit OOMKilled Non Compressible Resource @vitalethomas
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. Spring Boot 3 Native executables with GraalVM Slower Heavier Build

    Instant Startup Reduced Memory Consumption Instant Peak Performance Fewer Runtime Optimizations @vitalethomas
  16. 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
  17. Discount codes Manning • 35% discount code, valid for all

    products in all format • ctwdevcon22 • manning.com @vitalethomas