$30 off During Our Annual Pro Sale. View Details »

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

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

    • JVM system variables

    • Environment variables
    thomasvitale.com @vitalethomas

    View Slide

  9. Containerization
    thomasvitale.com @vitalethomas

    View 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 Slide

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

    View Slide

  12. Spring Boot on Kubernetes
    thomasvitale.com @vitalethomas

    View 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 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 Slide

  15. Externalized Configuration
    thomasvitale.com @vitalethomas

    View Slide

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

    View 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 Slide

  18. Graceful Shutdown
    thomasvitale.com @vitalethomas

    View 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 Slide

  20. Health Probes
    thomasvitale.com @vitalethomas

    View 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 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 Slide

  23. Spring Native
    thomasvitale.com @vitalethomas

    View 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 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 Slide

  26. GitOps & Kubernetes
    thomasvitale.com @vitalethomas

    View Slide

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

    View 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 Slide

  29. Observability
    thomasvitale.com @vitalethomas

    View Slide

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

    View Slide