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 full-size 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 full-size slide

  3. Cloud Native
    thomasvitale.com @vitalethomas

    View full-size 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 full-size 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 full-size 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 full-size slide

  7. Cloud Native Development
    thomasvitale.com @vitalethomas

    View full-size 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 full-size slide

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


    bootJar
    Maven


    spring-boot:repackage

    View full-size slide

  10. Containerization
    thomasvitale.com @vitalethomas

    View full-size 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 full-size slide

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

    View full-size slide

  13. buildpacks.io

    View full-size slide

  14. 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 full-size slide

  15. Spring Boot on Kubernetes
    thomasvitale.com @vitalethomas

    View full-size slide

  16. tanzucommunityedition.io

    View full-size slide

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


    Throttle
    Compressible


    Resource
    When limit hit


    OOMKilled
    Non


    Compressible


    Resource

    View full-size slide

  18. Externalized Configuration
    thomasvitale.com @vitalethomas

    View full-size slide

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

    View full-size slide

  20. 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 full-size slide

  21. 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 full-size slide

  22. Graceful Shutdown
    thomasvitale.com @vitalethomas

    View full-size slide

  23. 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 full-size slide

  24. Health Probes
    thomasvitale.com @vitalethomas

    View full-size slide

  25. 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 full-size slide

  26. 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 full-size slide

  27. Spring Native
    thomasvitale.com @vitalethomas

    View full-size slide

  28. Spring Native
    Native executables with GraalVM
    Slower

    Heavier

    Build
    Instant

    Startup
    Reduced

    Memory

    Consumption
    Instant

    Peak

    Performance
    Fewer

    Runtime

    Optimizations
    thomasvitale.com @vitalethomas

    View full-size slide

  29. 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 full-size slide

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

    View full-size slide