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

Implementing Kubernetes operators in Java with Micronaut - TechWeek Java Summit 2022

Implementing Kubernetes operators in Java with Micronaut - TechWeek Java Summit 2022

Micronaut is a modern, JVM-based, full stack Java framework designed for building modular, easily testable JVM applications

Micronaut supports a wide range of technologies, one of which is Kubernetes, allowing application developers to write cloud-native applications that are to be deployed on a Kubernetes cluster, and can benefit from features such as distributed configuration and service discovery. One of the features of the Micronaut Kubernetes module is the built-in support for implementing Kubernetes operators.

In this talk, Micronaut committer and Micronaut Kubernetes author Álvaro Sánchez-Mariscal, will demonstrate how to implement Kubernetes operators in Java with Micronaut.

More Decks by Álvaro Sánchez-Mariscal

Other Decks in Technology

Transcript

  1. Implementing Kubernetes operators in Java with Micronaut Java Summit |

    Bucharest Tech Week 2022 Álvaro Sánchez-Mariscal Principal Member of Technical Staff Micronaut Team, Oracle Labs 17 June 2022
  2. The following is intended to outline our general product direction.

    It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, timing, and pricing of any features or functionality described for Oracle’s products may change and remains at the sole discretion of Oracle Corporation. Safe harbor statement 2 Copyright © 2022, Oracle and/or its affiliates
  3. Álvaro Sánchez-Mariscal Principal Member of Technical Staff, Oracle Labs 3

    Copyright © 2022, Oracle and/or its affiliates Coming from Madrid Developer since 2001 (Java ☕️ stack) Micronaut core developer since its inception. • Maven Plugin. • Kubernetes. • Cache. • Guides. • Others: core, Gradle, AWS, GCP, Security, Test, etc. Speaker at conferences: Devoxx, GeeCON, JavaLand, JavaZone, Codemotion, Commit Conf, etc. @alvaro_sanchez
  4. 4 Copyright © 2022, Oracle and/or its affiliates. Micronaut® is

    a registered trademark of Object Computing, Inc. Use is for referential purposes and does not imply any endorsement or affiliation with any third-party product. Introduction
  5. Introduction to Micronaut Modern Java Framework Micronaut has been designed

    from scratch in 2017, focused on modern architectures like microservices and serverless, and with the cloud in mind. All application types Micronaut is a complete solution for any type of application: microservices, message-driven producers or consumers, command-line apps, serverless functions, etc. Highly optimised Micronaut leverages Java annotation processors and other optimisations to compute the framework infrastructure at compile-time, drastically reducing startup time and memory consumption. Copyright © 2022, Oracle and/or its affiliates 5
  6. AOT: Ahead Of Time Micronaut computes at build time: •

    All dependency and configuration injection. • Annotation metadata (meta annotations) • AOP proxies. • Bean introspections. • All other framework infrastructure. At runtime: • No reflection. • No proxy generation. • No dynamic classloading. • No classpath scanning. 6 Copyright © 2022, Oracle and/or its affiliates
  7. Copyright © 2022, Oracle and/or its affiliates 7 Any language,

    build tool, test framework, reactive library, cloud, …
  8. History 1. Inception in 2017. 2. 1.0.0: October 2018. 3.

    2.0.0: January 2020. 4. 3.0.0: August 2021. • 3.1.0: October 2021. • 3.2.0: November 2021. • 3.3.0: January 2022. • 3.4.0: March 2022. 5. Release schedule: • Major versions every 1 year. • Minor versions every 6 weeks. • Patch versions every 1-2 weeks. 6. Micronaut adheres to Semantic Versioning to bring stability and smooth upgrade paths to your applications. 8 Copyright © 2022, Oracle and/or its affiliates
  9. Micronaut features 1. Dependency injection. • Can use JSR-330 (@Inject)

    or Spring (@Autowired) annotations. 2. Configuration. • Properties, YAML, TOML, Groovy, Config4K. 3. Validation support. • Built-in: reflection free, faster startup, smaller JAR, reduced memory. • Hibernate Validation: full Bean Validation API compliance. 4. AOP: Aspect-Oriented Programming • Compile-time, reflection free. 9 Copyright © 2022, Oracle and/or its affiliates
  10. Micronaut features: HTTP Server 10 Copyright © 2022, Oracle and/or

    its affiliates
  11. Micronaut features: HTTP Client 11 Copyright © 2022, Oracle and/or

    its affiliates
  12. Micronaut features: message-driven applications Kafka • Producers • Consumers •

    Kafka Streams RabbitMQ • Producers • Consumers • RPC. MQTT • Publishers. • Subscribers. NATS • Producers • Consumers. Copyright © 2022, Oracle and/or its affiliates 12
  13. Micronaut features: data access 13 Copyright © 2022, Oracle and/or

    its affiliates
  14. Micronaut features: data access 14 Copyright © 2022, Oracle and/or

    its affiliates
  15. Micronaut features: security 1. Authentication providers. • Bult-in support for

    LDAP and OAuth 2.0 password grant flow. 2. Security rules • Configuration or annotation-based. 3. Authorization strategies. • Basic auth, session, JWT (JWKS, JWS), X.509. 4. OAuth 2.0. • Authorization code, client credentials and password grants. • OpenID Connect. • Ease of integration with providers such as Okta, Auth0, AWS Cognito, Keycloak and more. 15 Copyright © 2022, Oracle and/or its affiliates
  16. Micronaut features: misc 1. Distributed Tracing • Zipkin, Jaegger. 2.

    Service Discovery and Distributed Configuration • Consul, Eureka, Kubernetes. 3. Monitoring • Micrometer, JMX, Elasticsearch. 4. API development • GraphQL, GRPC, Open API. 5. Containers • Docker, Kubernetes, Testcontainers. 6. Cache • Jcache, Redis, Ehcache, Hazelcast, Infinispan, Oracle Coherence. 7. Email 8. Error handling 16 Copyright © 2022, Oracle and/or its affiliates
  17. Getting Started: Micronaut Launch 17 Copyright © 2022, Oracle and/or

    its affiliates https://launch.micronaut.io
  18. Getting Started: Micronaut CLI 18 Copyright © 2022, Oracle and/or

    its affiliates
  19. Getting started: Intellij IDEA 19 Copyright © 2022, Oracle and/or

    its affiliates
  20. Getting started: Visual Studio Code 20 Copyright © 2022, Oracle

    and/or its affiliates
  21. 21 Copyright © 2022, Oracle and/or its affiliates Kubernetes Support

    in Micronaut
  22. Service discovery: without Micronaut support 22 Copyright © 2022, Oracle

    and/or its affiliates
  23. Service discovery: with Micronaut support 23 Copyright © 2022, Oracle

    and/or its affiliates
  24. Service discovery 1. Allows Micronaut HTTP clients to discover Kubernetes

    services (kind: Service) 2. Micronaut will query the Kubernetes API to fetch the list of services and watch for changes. • By default, will search in the current namespace, but can be configured to look in different ones. • If the service is a Multi-port one, the client can be configured to use one specific port. • Available services can be filtered by using includes/excludes lists or labels. 3. Service discovery modes: • Endpoint (default): reads from kind: Endpoints objects to compute a list of instances that are load balanced by the Micronaut HTTP client. • Service: uses the ClusterIP from the service. Load balancing is handled by Kubernetes’ kube-proxy. 24 Copyright © 2022, Oracle and/or its affiliates
  25. Distributed configuration 25 Copyright © 2022, Oracle and/or its affiliates

  26. Distributed configuration 1. Reads Kubernetes kind: ConfigMap and kind: Secret,

    and makes them available as PropertySource’s 2. Micronaut will query the Kubernetes API to fetch the list of config maps / secrets, and watch for changes. • By default, will search in the current namespace, but can be configured to look in different ones. • Available objects can be filtered by using includes/excludes lists or labels. 3. Config maps / secrets can also be read from mounted volumes (no Kubernetes API). 26 Copyright © 2022, Oracle and/or its affiliates
  27. Health checks 27 Copyright © 2022, Oracle and/or its affiliates

    1. Probes communication with the Kubernetes API. 2. Provides some additional information about the pod where the application is running from. 3. Lists all the services discovered and their resolved URL endpoints.
  28. Kubernetes Java Client 28 Copyright © 2022, Oracle and/or its

    affiliates io.kubernetes.client.openapi.apis.CoreV1Api dependency injected
  29. Kubernetes Java Client 1. Allows you to use dependency injection

    to get a ready-to-use client object from the Official Kubernetes Java client library. 2. Supports multiple authentication options. It works out-of-the-box. Can be programmatically customised. 3. Micronaut implements reactive variants with Reactor or RxJava 2/3. 4. The underlying HTTP client can be programmatically customised if needed. 29 Copyright © 2022, Oracle and/or its affiliates
  30. Kubernetes Operator support 1. Micronaut allows you to implement the

    following Kubernetes operators building blocks: • Informers. • Reconcilers. • Leader election. • Lock identies. 2. Allows you to work with both core and custom resource definitions (CRD). 30 Copyright © 2022, Oracle and/or its affiliates
  31. Kubernetes Operator support 31 Copyright © 2022, Oracle and/or its

    affiliates
  32. Kubernetes Operator support 32 Copyright © 2022, Oracle and/or its

    affiliates
  33. Demo Kubernetes Support in Micronaut 33 Copyright © 2022, Oracle

    and/or its affiliates
  34. 34 Copyright © 2022, Oracle and/or its affiliates

  35. What is GraalVM 1. Drop-in replacement for Oracle Java 8

    / 11 / 17. • Run your Java application faster. 2. Ahead-of-time compilation for Java • Create standalone binaries with low footprint. 3. High-performance JavaScript, Python, Ruby, R, … • The first VM for true polyglot programming. • Implement your own language or DSL. 35 Copyright © 2022, Oracle and/or its affiliates
  36. What is GraalVM 36 Copyright © 2022, Oracle and/or its

    affiliates
  37. Micronaut and GraalVM 6ms As low as startup time 18MB

    Consuming memory footprint >30% Increased throughput up to and reduced latency Copyright © 2022, Oracle and/or its affiliates 37
  38. Micronaut and GraalVM 1. The best integration possibly, supported by

    teams working together at Oracle Labs. • GraalVM EE includes optimisations for Micronaut for increased performance and throughput. • GraalVM EE license included in Oracle Cloud. 2. Micronaut is ready for GraalVM Native Image since day 1. • No reflection, no runtime proxies, no bytecode generation, no dynamic classloading. 3. GraalVM Extenstion Pack for Visual Studio Code. 38 Copyright © 2022, Oracle and/or its affiliates
  39. Micronaut and GraalVM 39 Copyright © 2022, Oracle and/or its

    affiliates In Maven: In Gradle:
  40. Micronaut, GraalVM and Kubernetes 1. Micronaut and GraalVM is a

    great combination for Kubernetes workloads. 2. You can get sub-second startup times for your containers. 3. Even bigger benefits for serverless deployments when you are billed by resource utilisation. 40 Copyright © 2022, Oracle and/or its affiliates
  41. Q &A 41 Copyright © 2022, Oracle and/or its affiliates

  42. Mulțumesc foarte mult! Álvaro Sánchez-Mariscal 42 Copyright © 2022, Oracle

    and/or its affiliates @alvaro_sanchez
  43. Grab your stickers! Álvaro Sánchez-Mariscal 43 Copyright © 2022, Oracle

    and/or its affiliates @alvaro_sanchez
  44. None
  45. Our mission is to help people see data in new

    ways, discover insights, unlock endless possibilities.