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

Cloud Native with Java, Spring Boot and Kubernetes

Cloud Native with Java, Spring Boot and Kubernetes

Thomas Vitale

July 02, 2021
Tweet

More Decks by Thomas Vitale

Other Decks in Programming

Transcript

  1. Thomas Vitale
    Incontro DevOps Italia
    July 2nd, 2021
    Cloud Native with Java,
    Spring Boot and Kubernetes
    From development to production
    @vitalethomas

    View full-size slide

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

    • Spring, Cloud Native, DevOps,
    Kubernetes, Application Security.

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

    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 (“fat-JAR”)

    • Externalized con
    fi
    guration
    • Property
    fi
    les for default values

    • JVM system variables

    • Environment variables
    thomasvitale.com @vitalethomas

    View full-size slide

  9. Containerization
    thomasvitale.com @vitalethomas

    View full-size slide

  10. 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

  11. Containerize Spring Boot Applications
    Docker
    fi
    les
    Cloud Native Buildpacks
    Jib
    thomasvitale.com @vitalethomas

    View full-size slide

  12. Spring Boot on Kubernetes
    thomasvitale.com @vitalethomas

    View full-size slide

  13. Spring Boot on Kubernetes
    Kubernetes manifests for deploying applications
    • Deployment -> deploy the application (with replicas)

    • Service -> expose the application to the inside of the cluster

    • Ingress -> expose the application to the Internet
    thomasvitale.com @vitalethomas

    View full-size slide

  14. Deploying Spring Boot Applications
    Computational resource con
    fi
    guration
    • Requests are the resources
    guaranteed to the application
    container.

    • Limits de
    fi
    ne the maximum
    resources an application container
    can get.

    • CPU is compressible.

    • When limit hit: throttle.

    • For JVM containers, no limit for
    startup boost.

    • Memory is non-compressible.

    • When limit hit: OOMKilled

    • For JMV containers, same
    value for requests and limits.
    thomasvitale.com @vitalethomas

    View full-size slide

  15. Externalized Configuration
    thomasvitale.com @vitalethomas

    View full-size slide

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

    View full-size slide

  17. ConfigMaps and Secrets
    Con
    fi
    guration and credentials
    • Con
    fi
    gMaps
    • Environment variables

    • Volume mounts

    • Secrets
    • Environment variables

    • Consider a backend like Vault
    for actual encryption or Sealed
    Secrets
    thomasvitale.com @vitalethomas

    View full-size slide

  18. Graceful Shutdown
    thomasvitale.com @vitalethomas

    View full-size slide

  19. 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

  20. Health Probes
    thomasvitale.com @vitalethomas

    View full-size slide

  21. 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

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

    View full-size slide

  23. Spring Native
    thomasvitale.com @vitalethomas

    View full-size slide

  24. Spring Native
    Native executables with GraalVM
    • Bene
    fi
    ts
    • Instant startup

    • Instant peak performance

    • Reduced memory consumption

    • Tradeo
    ff
    s
    • Slower and heavier build process

    • Fewer runtime optimizations
    thomasvitale.com @vitalethomas

    View full-size slide

  25. 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

  26. GitOps & Kubernetes
    thomasvitale.com @vitalethomas

    View full-size slide

  27. GitOps - Cloud Native Operations
    https://www.weave.works/technologies/gitops/

    View full-size slide

  28. GitOps - Configuration
    helm upgrade -i flux fluxcd/flux \


    --set git.user=$GITHUB_USER \


    --set [email protected] \


    --set [email protected]:$GITHUB_USER/spring-boot-
    kubernetes-incontro-devops-2021 \


    --set git.path="k8s" \


    --set git.branch="main" \


    --namespace flux


    thomasvitale.com @vitalethomas

    View full-size slide

  29. Observability
    thomasvitale.com @vitalethomas

    View full-size slide

  30. Thomas Vitale
    Incontro DevOps Italia
    July 2nd, 2021
    Cloud Native with Java,
    Spring Boot and Kubernetes
    From development to production
    @vitalethomas

    View full-size slide