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

Cloud Native with Spring Boot and Kubernetes

Thomas Vitale
November 10, 2021

Cloud Native with Spring Boot and Kubernetes

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 using Reactive Spring, which provides better performance, resilience, and efficiency. You’ll then see how to containerize them, configure them through the natively supported ConfigMaps and Secrets, and deploy them to a Kubernetes cluster. Finally, he’ll show how to use Spring Native to build GraalVM native executables.

Thomas Vitale

November 10, 2021
Tweet

More Decks by Thomas Vitale

Other Decks in Technology

Transcript

  1. Thomas Vitale
    GOTO Copenhagen
    Nov 10th, 2021
    Cloud Native with
    Spring Boot and Kubernetes
    From development to production
    @vitalethomas

    View Slide

  2. Thomas Vitale
    • Senior Software Engineer at
    Systematic, Denmark.

    • Author of “Cloud Native Spring
    in Action” (Manning).

    • Spring Security and Spring
    Cloud contributor.
    About Me
    thomasvitale.com

    View Slide

  3. Cloud Native
    thomasvitale.com @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
    thomasvitale.com @vitalethomas

    View Slide

  5. The Three P’s of Cloud Native Applications
    Properties
    Place Practices
    Private Cloud


    Public Cloud


    Hybrid Cloud
    Scalability


    Loose Coupling


    Resilience


    Manageability


    Observability


    Security
    Automation


    Continuous Delivery


    DevOps
    thomasvitale.com @vitalethomas

    View Slide

  6. From Development to Production
    Cloud native journey in less than 45 minutes
    thomasvitale.com @vitalethomas
    Spring Boot
    Development
    Cloud Native
    Buildpacks
    Containerization
    Kubernetes
    Deployment

    View Slide

  7. Cloud Native Development
    thomasvitale.com @vitalethomas

    View Slide

  8. 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
    thomasvitale.com @vitalethomas

    View Slide

  9. Packaging Spring Boot
    Standalone JAR
    thomasvitale.com @vitalethomas
    JAR
    Gradle


    bootJar
    Maven


    spring-boot:repackage

    View Slide

  10. Containerization
    thomasvitale.com @vitalethomas

    View Slide

  11. 1 Don’t use fat JARs
    2 Optimize build/runtime performance
    3 Don’t run as root or include secrets
    thomasvitale.com @vitalethomas

    View Slide

  12. Containerize Java Applications
    Docker
    fi
    les
    Cloud Native Buildpacks
    Jib
    thomasvitale.com @vitalethomas

    View Slide

  13. buildpacks.io

    View Slide

  14. paketo.io

    View Slide

  15. Packaging Spring Boot
    JAR & Container Image
    thomasvitale.com @vitalethomas
    JAR
    Container Image
    Gradle


    bootJar
    Maven


    spring-boot:repackage
    Gradle


    bootBuildImage
    Maven


    spring-boot:build-image

    View Slide

  16. Spring Boot on Kubernetes
    thomasvitale.com @vitalethomas

    View Slide

  17. tanzucommunityedition.io

    View Slide

  18. knative.dev

    View Slide

  19. Configuring Resources
    CPU & Memory
    thomasvitale.com @vitalethomas
    CPU
    Memory
    When limit hit


    Throttle
    Compressible


    Resource
    When limit hit


    OOMKilled
    Non


    Compressible


    Resource

    View Slide

  20. Externalized Configuration
    thomasvitale.com @vitalethomas

    View Slide

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

    View Slide

  22. Configuration Options
    thomasvitale.com @vitalethomas
    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

    View Slide

  23. ConfigMaps & Secrets
    thomasvitale.com @vitalethomas
    Mount the volume

    to the /config path,

    where Spring Boot will

    automatically read

    property
    fi
    les.
    Load the Con
    fi
    gMap

    In a volume

    View Slide

  24. Graceful Shutdown
    thomasvitale.com @vitalethomas

    View Slide

  25. 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
    thomasvitale.com @vitalethomas

    View Slide

  26. Health Probes
    thomasvitale.com @vitalethomas

    View Slide

  27. 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.
    thomasvitale.com @vitalethomas

    View Slide

  28. Liveness and Readiness Probes
    thomasvitale.com @vitalethomas
    When not available,

    Kubernetes will restart

    the container
    When not ready,

    Kubernetes will not send

    any tra
    ff
    i
    c to the container

    View Slide

  29. Spring Native
    thomasvitale.com @vitalethomas

    View Slide

  30. Spring Native
    Native executables with GraalVM
    Slower

    Heavier

    Build
    Instant

    Startup
    Reduced

    Memory

    Consumption
    Instant

    Peak

    Performance
    Fewer

    Runtime

    Optimizations
    thomasvitale.com @vitalethomas

    View Slide

  31. From Development to Production
    Cloud native journey in less than 45 minutes
    thomasvitale.com @vitalethomas
    Spring Boot
    Development
    Cloud Native
    Buildpacks
    Containerization
    Kubernetes
    Deployment

    View Slide

  32. Thomas Vitale
    GOTO Copenhagen
    Nov 10th, 2021
    Cloud Native with
    Spring Boot and Kubernetes
    From development to production
    @vitalethomas

    View Slide