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

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
Tweet

More Decks by Thomas Vitale

Other Decks in Technology

Transcript

  1. Thomas Vitale
    DevCon
    Nov 9th, 2022
    Kubernetes Native Java
    With Spring Boot
    @vitalethomas

    View Slide

  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

    View Slide

  3. Cloud Native
    @vitalethomas

    View Slide

  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

    View Slide

  5. From Development to Production
    A Cloud Native Journey
    Spring Boot
    Development
    Cloud Native
    Buildpacks
    Containerization
    Kubernetes
    Deployment
    @vitalethomas

    View Slide

  6. Cloud Native Development
    @vitalethomas

    View Slide

  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

    View Slide

  8. Packaging Spring Boot
    Standalone JAR
    JAR
    Gradle


    bootJar
    Maven


    spring-boot:repackage
    @vitalethomas

    View Slide

  9. Containerization
    @vitalethomas

    View Slide

  10. Image
    pack build
    Cloud Native Buildpacks
    From source code to container image
    @vitalethomas

    View Slide

  11. Packaging Spring Boot
    JAR & Container Image
    JAR
    Container Image
    Gradle


    bootJar
    Maven


    spring-boot:repackage
    Gradle


    bootBuildImage
    Maven


    spring-boot:build-image
    @vitalethomas

    View Slide

  12. Spring Boot on Kubernetes
    @vitalethomas

    View Slide

  13. Knative
    Serverless experience on Kubernetes
    @vitalethomas

    View Slide

  14. Serverless Architectures
    Developers focus on code
    Focus on business logic
    Developer
    Platform
    Infrastructure

    Provisioning
    Workload

    Management
    Dynamic

    Scaling
    @vitalethomas

    View Slide

  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

    View Slide

  16. Configuring Resources
    CPU & Memory
    CPU
    Memory
    When limit hit


    Throttle
    Compressible


    Resource
    When limit hit


    OOMKilled
    Non


    Compressible


    Resource
    @vitalethomas

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  20. Externalised Configuration
    @vitalethomas

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  25. Native Images
    @vitalethomas

    View Slide

  26. Spring Boot 3
    Native executables with GraalVM
    Slower

    Heavier

    Build
    Instant

    Startup
    Reduced

    Memory

    Consumption
    Instant

    Peak

    Performance
    Fewer

    Runtime

    Optimizations
    @vitalethomas

    View Slide

  27. Resources
    @vitalethomas

    View Slide

  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

    View Slide

  29. https://github.com/ThomasVitale/awesome-spring

    View Slide

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

    • ctwdevcon22


    • manning.com
    @vitalethomas

    View Slide

  31. Thomas Vitale
    DevCon
    Nov 9th, 2022
    Kubernetes Native Java
    With Spring Boot
    @vitalethomas
    @[email protected]

    View Slide