Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

Spring Boot Loves K8s

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Cargando en…3
×

Eche un vistazo a continuación

1 de 43 Anuncio

Más Contenido Relacionado

Presentaciones para usted (20)

Similares a Spring Boot Loves K8s (20)

Anuncio

Más de VMware Tanzu (20)

Más reciente (20)

Anuncio

Spring Boot Loves K8s

  1. 1. Spring Boot loves k8s September 2–3, 2020 springone.io #session-spring-boot-loves-k8s on Slack 1 Stéphane Nicoll @snicoll Brian Clozel @bclozel
  2. 2. Safe Harbor Statement The following is intended to outline the general direction of VMware's offerings. It is intended for information purposes only and may not be incorporated into any contract. Any information regarding pre-release of VMware offerings, future updates or other planned modifications is subject to ongoing evaluation by VMware and is subject to change. This information is provided without warranty or any kind, express or implied, and is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions regarding VMware's offerings. These purchasing decisions should only be based on features currently available. The development, release, and timing of any features or functionality described for VMware's offerings in this presentation remain at the sole discretion of Pivotal. Pivotal has no obligation to update forward looking information in this presentation. 2
  3. 3. k8s implementation details
  4. 4. Distributed systems best practices
  5. 5. Natural deployment to k8s
  6. 6. Agenda Showcasing Spring Boot 2.3 features during a live coding session ● The “Scribe” application ● Efficient Container images ● Liveness and Readiness ● Graceful Shutdown ● Next in Spring Boot 2.4+ 6
  7. 7. Markdown editor with spell check 7
  8. 8. Markdown editor with spell check 7
  9. 9. Markdown editor with spell check 7
  10. 10. Markdown editor with spell check 7
  11. 11. A distributed system! 8 Scribe MarkdownConverter ● Web UI ● Spell check ● Calls Converter + Fallback ● HTTP endpoint ● Markdown to HTML
  12. 12. Efficient Container images
  13. 13. Very Basic Dockerfile for Java apps 10 FROM openjdk:8-jre-alpine WORKDIR application ARG JAR_FILE=scribe/target/scribe-*.jar COPY ${JAR_FILE} application.jar ENTRYPOINT ["java","-jar","application.jar"]
  14. 14. Layers in Container images 11 FROM … [FROM CACHE] COPY … [FROM CACHE] COPY … [REBUILDING] RUN … Layers represent changes/intermediate images (like git commits) When rebuilding an image, layers can be cached and reused if their content did not change.
  15. 15. Optimizing Container images 12 FROM … [FROM CACHE] COPY application.jar [REBUILDING] Regrouping resources with similar lifecycle will improve image build time and storage efficiency. In our current Dockerfile, the entire layer needs to be rebuilt for any change in the application
  16. 16. https://github.com/wagoodman/dive 13
  17. 17. https://github.com/wagoodman/dive 13
  18. 18. 14 Anatomy of a Spring Boot Jar 6 . ├── BOOT-INF │   ├── classes │   │   ├── application.properties │   │   ├── io/spring/sample/scribe │   │   │  ├── EditorController.class │   │   │   ├── ScribeApplication.class │   │   │   ├── … │   └── lib │   ├── bulma-0.9.0.jar │   ├── jackson-databind-2.11.2.jar │   ├── spring-boot-2.3.3.RELEASE.jar
  19. 19. 14 Anatomy of a Spring Boot Jar 6 │   │   │   ├── ScribeApplication.class │   │   │   ├── … │   └── lib │   ├── bulma-0.9.0.jar │   ├── jackson-databind-2.11.2.jar │   ├── spring-boot-2.3.3.RELEASE.jar │   ├── … ├── META-INF │   ├── MANIFEST.MF │   └── spring-configuration-metadata.json └── org/springframework/boot/loader ├── ClassPathIndexFile.class ├── JarLauncher.class ├── …
  20. 20. Layered container images 15 FROM … COPY --from=builder source/snapshot-dependencies/ ./ COPY --from=builder source/spring-boot-loader/ ./ COPY --from=builder source/dependencies/ ./ Spring Boot can build efficient container images. Developers can customize the layer arrangement and reorder, add their own… Using the Maven/Gradle build plugins. COPY --from=builder source/application/ ./
  21. 21. Spring Boot + Buildpacks No Dockerfile required! Build locally with the CLI: 16 ./mvnw spring-boot:build-image ./gradlew bootBuildImage Also, delegate to your company’s builder instance in your build pipeline.
  22. 22. Cloud Native Buildpacks With buildpacks.io, you can delegate container image building for: • Balanced control between app devs and platform operators • Security and compliance requirements handled in one place • Easier maintenance/upgrades 17
  23. 23. What about other solutions? Buildpacks, Dockerfiles, Jib, s2i, ko… They have different approaches and features, see https://buildpacks.io/features/ Choose what fits best for your team! 18
  24. 24. Next: Spring to image Later today, check out the “Spring to image” session with Ben Hale. https://springone.io/2020/sessions/spring-to-image This session will cover Spring Boot build plugins, the pack CLI, the kpack Kubernetes service and more! 19
  25. 25. Liveness and Readiness 20
  26. 26. Liveness and Readiness 1. New concepts supported in Spring Boot core. 2. Complement the existing application Health support in Actuator. 3.Empower developers with ApplicationAvailability. 21
  27. 27. Liveness and Readiness states Liveness “CORRECT” if the internal state of the app is fine. External dependencies or the service itself might not respond correctly still. “BROKEN” if the internal state of the application is broken and restarting is the only way to fix it. 22 Readiness “ACCEPTING_TRAFFIC” is a way to tell load balancers that the app is ready to serve requests. The app is “REFUSING_TRAFFIC” if it considers that its load is too high, or depending on its lifecycle stage (starting up, shutting down).
  28. 28. Liveness and Readiness Probes Liveness and Readiness states are available as health groups. Enabled automatically on k8s, or with the config property: 23 https://example.org/actuator/health/liveness https://example.org/actuator/health/readiness Probes are available here and in sync with the application lifecycle: management.endpoint.health.probes.enabled=true
  29. 29. Probes as Health Groups Liveness and readiness probes are using the Health Groups feature. You can configure additional checks to a probe: 24 management.endpoint.health.group.readiness.include=readinessState,customCheck ⚠ You should be careful about checking for external state in probes.
  30. 30. ApplicationAvailability 25 @Component public class LocalCacheVerifier { private final ApplicationEventPublisher eventPublisher; public void checkLocalCache() { try { //... } catch (CacheCompletelyBrokenException ex) { AvailabilityChangeEvent.publish(this.eventPublisher, ex, LivenessState.BROKEN); } } } // see more in reference docs
  31. 31. Graceful Shutdown 26
  32. 32. Shutting down app with active requests 27 Scribe MarkdownConverter MarkdownConverter MarkdownConverter HTTP POST /convert 1. Processing…
  33. 33. Shutting down app with active requests 27 Scribe MarkdownConverter MarkdownConverter MarkdownConverter HTTP POST /convert 1. Processing… 2. Shutdown!
  34. 34. Graceful Shutdown 28 Scribe MarkdownConverter HTTP POST /convert 1. Processing… MarkdownConverter MarkdownConverter
  35. 35. Graceful Shutdown 28 Scribe MarkdownConverter HTTP POST /convert 1. Processing… 2. Stop accepting MarkdownConverter MarkdownConverter
  36. 36. Graceful Shutdown 28 Scribe MarkdownConverter HTTP POST /convert 1. Processing… 3. Done 2. Stop accepting MarkdownConverter MarkdownConverter
  37. 37. Graceful Shutdown 28 Scribe MarkdownConverter HTTP POST /convert 1. Processing… 3. Done 2. Stop accepting MarkdownConverter MarkdownConverter 4.Shutdown!
  38. 38. Configuring Graceful Shutdown Enabling Graceful Shutdown and configuring the grace period: 29 server.shutdown=graceful spring.lifecycle.timeout-per-shutdown-phase=20s
  39. 39. Next in Spring Boot 2.4+ 30
  40. 40. Config file processing Volume mounted configuration trees, multi-document properties files, profile groups, etc. See config file processing blog post. 31 spring.config.activate.on-cloud-platform=kubernetes spring.config.import=configtree:/etc/config spring.config.activate.on-cloud-platform=kubernetes spring.config.import=configtree:/etc/config spring.config.activate.on-cloud-platform=kubernetes spring.config.import=configtree:/etc/config spring.config.activate.on-cloud-platform=kubernetes spring.config.import=configtree:/etc/config spring.config.activate.on-cloud-platform=kubernetes spring.config.import=configtree:/etc/config etc/ +- config/ +- my/ | +- application +- test
  41. 41. Graceful shutdown improvements The team is considering adding a shutdown delay option because most platforms still route traffic to while routing state is converging. Currently you can use a PreStop hook to delay the shutdown sequence. 32
  42. 42. Layered JARs enabled by default As of 2.4.0, Spring Boot JARs will ship with the layers.idx by default. Useful metadata for tools in your CI/CD pipeline. 33
  43. 43. Stay Connected. Q&A #session-spring-boot-loves-k8s on Slack “Spring to Image” session with Ben Hale Slides and code: https://springone.io/2020/sessions/spring-boot-loves-k8s https://github.com/snicoll/spring-boot-loves-k8s #springone@s1p

×