Slide 1

Slide 1 text

Implementing Kubernetes operators in Java with the Micronaut® framework Álvaro Sánchez-Mariscal Principal Member of Technical Staff Oracle @alvaro_sanchez

Slide 2

Slide 2 text

Álvaro Sánchez-Mariscal Principal Member of Technical Staff, Oracle • Coming from Madrid • Developer since 2001 (Java stack) • Micronaut core developer since its inception (2017). • Author: Maven Plugin, Object Storage, Kubernetes, Cache, Control Panel. • Others: Core, Gradle, AWS, GCP, Azure, Security, Test, etc. • Currently at Oracle Labs: • Micronaut and Graal Development Kit for Micronaut (GDK). • GraalVM Native Build Tools. • Speaker at conferences: Devoxx, GeeCON, JavaLand, JavaZone, jPrime, Codemotion, Commit Conf, etc. @alvaro_sanchez

Slide 3

Slide 3 text

#PleaseDon’tGo Copyright © 2024, Oracle and/or its affiliates 3

Slide 4

Slide 4 text

Slides 4 Copyright © 2024, Oracle and/or its affiliates Demo

Slide 5

Slide 5 text

Copyright © 2024, 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. 5

Slide 6

Slide 6 text

Introduction to Micronaut Copyright © 2024, Oracle and/or its affiliates 6 Micronaut is a complete solution for any type of application: microservices, message-driven producers or consumers, command-line apps, serverless functions, etc. All application types Micronaut leverages Java annotation processors and other optimisations to compute the framework infrastructure at compile-time, drastically reducing startup time and memory consumption. Highly optimised Modern, open-source Java Framework Micronaut has been designed from scratch in 2017, focused on modern architectures like microservices and serverless, and with the cloud in mind.

Slide 7

Slide 7 text

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. AOT: Ahead Of Time Copyright © 2024, Oracle and/or its affiliates 7 Source code @Singleton class MySvc {} Bytecode class $MySvc$Definition {} class $MySvc$Definition$Reference {} Source code @Builder record Person() {} Source code @Generated class PersonBuilder() {} compilation compilation

Slide 8

Slide 8 text

8 Any language, build tool, test framework, reactive library, cloud, … Copyright © 2024, Oracle and/or its affiliates

Slide 9

Slide 9 text

Micronaut Hello World 9 Copyright © 2024, Oracle and/or its affiliates

Slide 10

Slide 10 text

Micronaut features: HTTP Client 10 Copyright © 2024, Oracle and/or its affiliates Implemented at compile time

Slide 11

Slide 11 text

Micronaut features: message-driven applications Kafka • Producers. • Consumers. • Kafka Streams. RabbitMQ • Producers. • Consumers. • RPC. MQTT • Publishers. • Subscribers. NATS • Producers. • Consumers. Copyright © 2024, Oracle and/or its affiliates 11

Slide 12

Slide 12 text

Micronaut features: data access 12 Copyright © 2024, Oracle and/or its affiliates

Slide 13

Slide 13 text

Micronaut features: data access 13 Copyright © 2024, Oracle and/or its affiliates Interface implemented at compile time Query generated from the method name, compile-time validated Can have custom queries, inserts, etc

Slide 14

Slide 14 text

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. 14 Copyright © 2024, Oracle and/or its affiliates

Slide 15

Slide 15 text

Micronaut features: Test Resources 1. Automatic provisioning of external resources needed during development or testing. • Containers, binaries, etc. 2. Built-in support: 3. Integrated with JUnit Platform (JUnit / Spock / Kotest) for zero-configuration Testcontainers. 15 Copyright © 2024, Oracle and/or its affiliates • MariaDB • MySQL • Oracle • PostgreSQL • SQL Server • Elasticsearch • Redis • MongoDB • Neo4j • Hashicorp Vault • Kafka • RabbitMQ • MQTT • Localstack

Slide 16

Slide 16 text

Micronaut features: Serialization 1. Drop-in replacement for Jackson Databind, compile-time and reflection free. 2. Supports (most of) Jackson, JSON-B and BSON annotations. 3. Why? • Memory performance: 10x smaller runtime footprint. • Security: serializable classes must be opt-in. • Type-safety: Micronaut Serialization performs checks at compile-time (vs Jackson runtime exceptions). • Runtime portability: Micronaut Serialization at runtime supports different annotation sets. 16 Copyright © 2024, Oracle and/or its affiliates

Slide 17

Slide 17 text

Micronaut features: misc 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 Jakarta Validation API compliance. 4. AOP: Aspect-Oriented Programming. • Compile-time, reflection free. 17 Copyright © 2024, Oracle and/or its affiliates

Slide 18

Slide 18 text

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. 18 Copyright © 2024, Oracle and/or its affiliates

Slide 19

Slide 19 text

Getting Started: Micronaut Guides 19 Copyright © 2024, Oracle and/or its affiliates https://guides.micronaut.io

Slide 20

Slide 20 text

Getting Started: Micronaut Launch 20 Copyright © 2024, Oracle and/or its affiliates https://launch.micronaut.io

Slide 21

Slide 21 text

Getting Started: Micronaut CLI 21 Copyright © 2024, Oracle and/or its affiliates

Slide 22

Slide 22 text

Getting Started: IntelliJ IDEA 22 Copyright © 2024, Oracle and/or its affiliates

Slide 23

Slide 23 text

Getting Started: Visual Studio Code 23 Copyright © 2024, Oracle and/or its affiliates

Slide 24

Slide 24 text

Micronaut 4: what’s new 1. Java 17 required. • Virtual threads support (Project Loom). • @Client implementation based on java.net.http.HttpClient (JEP 321) • For older versions of Java use Micronaut 3.x. • Other languages • Kotlin 1.8, KSP support. • Apache Groovy 4. 2. GraalVM improvements. • Reachability metadata enabled. • Improved build times and reduced memory consumption. 3. Micronaut Data v4 • Hibernate 6. 24 Copyright © 2024, Oracle and/or its affiliates

Slide 25

Slide 25 text

Micronaut 4: what’s new 3. Smaller, lighter runtime. • Performance closer to raw Netty (~200ms startup). • Some modules spun off core: Service Discovery, Retry, Session, Validation, Websocket. • Some dependencies now optional: Jackson, SnakeYAML, Caffeine. 4. Other features: • HTTP client/server filter methods: annotation-based and without reactive APIs. • Annotation-based CORS configuration. • HTTP/3 support. • Prefer Micronaut Serialization over Jackson. • Disabled cloud environment deduction by default. 25 Copyright © 2024, Oracle and/or its affiliates

Slide 26

Slide 26 text

Micronaut 4: what’s new 5. Compile-time expression language 26 Copyright © 2024, Oracle and/or its affiliates Checked at compile time Checked at compile time

Slide 27

Slide 27 text

Micronaut 4: what’s new 6. Bean mappers: built-in, type-safe alternative to MapStruct for type mapping built on EL. 27 Copyright © 2024, Oracle and/or its affiliates

Slide 28

Slide 28 text

Micronaut 4 Control Panel 28 Copyright © 2024, Oracle and/or its affiliates

Slide 29

Slide 29 text

Micronaut 4 coming soon: source generation 29 Copyright © 2024, Oracle and/or its affiliates Generates PersonBuilder at compile-time

Slide 30

Slide 30 text

Copyright © 2024, Oracle and/or its affiliates 30 Kubernetes Support in Micronaut

Slide 31

Slide 31 text

Service discovery: without Micronaut support 31 Copyright © 2024, Oracle and/or its affiliates

Slide 32

Slide 32 text

Service discovery: with Micronaut support 32 Copyright © 2024, Oracle and/or its affiliates

Slide 33

Slide 33 text

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. 33 Copyright © 2024, Oracle and/or its affiliates

Slide 34

Slide 34 text

Distributed configuration 34 Copyright © 2024, Oracle and/or its affiliates

Slide 35

Slide 35 text

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). 35 Copyright © 2024, Oracle and/or its affiliates

Slide 36

Slide 36 text

Health checks 36 Copyright © 2024, 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.

Slide 37

Slide 37 text

Kubernetes Java Client 37 Copyright © 2024, Oracle and/or its affiliates io.kubernetes.client.openapi.apis.CoreV1Api dependency injected

Slide 38

Slide 38 text

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. 38 Copyright © 2024, Oracle and/or its affiliates

Slide 39

Slide 39 text

Kubernetes Operator support 1. Micronaut allows you to implement the following Kubernetes operators building blocks: • Informers. • Reconcilers. • Leader election. 2. Allows you to work with both core and custom resource definitions (CRD). 39 Copyright © 2024, Oracle and/or its affiliates

Slide 40

Slide 40 text

Kubernetes Operator support: informers 40 Copyright © 2024, Oracle and/or its affiliates

Slide 41

Slide 41 text

Kubernetes Operator support: reconcilers 41 Copyright © 2024, Oracle and/or its affiliates

Slide 42

Slide 42 text

Graal A full stack for the development and deployment of high performance Java cloud native applications

Slide 43

Slide 43 text

Copyright © 2024, Oracle and/or its affiliates 43

Slide 44

Slide 44 text

What is Graal Development Kit for Micronaut? Copyright © 2024, Oracle and/or its affiliates 44 BUILT FOR GRAALVM NATIVE IMAGE Easily compile ahead-of-time with GraalVM Native Image into small executables that start instantly, and use less memory/CPU. CLOUD-AGNOSTIC MODULES A curated set of Micronaut modules that provide platform-independent support for core cloud services – object store, secrets, streaming, and more. DEV TOOLS AND VS CODE EXTENSIONS Dev tools to generate multicloud application starter templates. VS Code extensions for local development and cloud deployment.

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

46 Copyright © 2024, Oracle and/or its affiliates

Slide 47

Slide 47 text

47 Copyright © 2024, Oracle and/or its affiliates

Slide 48

Slide 48 text

Copyright © 2024, Oracle and/or its affiliates 48

Slide 49

Slide 49 text

What is GraalVM 49 Copyright © 2024, Oracle and/or its affiliates

Slide 50

Slide 50 text

Native Image Goals Low Resource Usage Start Fast Compact Packaging Minimize Vulnerability Copyright © 2024, Oracle and/or its affiliates 50

Slide 51

Slide 51 text

Micronaut and GraalVM 6ms As low as startup time 18MB Consuming memory footprint >30% Increased throughput up to and reduced latency

Slide 52

Slide 52 text

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 tooling for Visual Studio Code and Intellij IDEA. 52 Copyright © 2024, Oracle and/or its affiliates

Slide 53

Slide 53 text

GraalVM Reachability Metadata Repository Community-driven collection of GraalVM reachability metadata for open-source libraries. • Actively maintained by a collective effort of VMware, Oracle and others. • Enabled in GraalVM Native Build Tools (Maven and Gradle plugins). • Integrated by default in Spring Boot and Micronaut. 53 Copyright © 2024, Oracle and/or its affiliates

Slide 54

Slide 54 text

Micronaut is the fastest to startup 54 Copyright © 2024, Oracle and/or its affiliates Source: https://speakerdeck.com/mraible/comparing-native-java-rest-api-frameworks-jchampions-conference-2024

Slide 55

Slide 55 text

Micronaut is the fastest to startup 55 Copyright © 2024, Oracle and/or its affiliates Source: https://speakerdeck.com/mraible/comparing-native-java-rest-api-frameworks-jchampions-conference-2024

Slide 56

Slide 56 text

Micronaut consumes the less memory 56 Copyright © 2024, Oracle and/or its affiliates Source: https://speakerdeck.com/mraible/comparing-native-java-rest-api-frameworks-jchampions-conference-2024

Slide 57

Slide 57 text

Micronaut and GraalVM powering Disney+ 57 Copyright © 2024, Oracle and/or its affiliates https://aws.amazon.com/blogs/opensource/improving-developer-productivity-at-disney-with-serverless-and-open-source/

Slide 58

Slide 58 text

Copyright © 2024, Oracle and/or its affiliates 58 Demo Kubernetes operator in Java

Slide 59

Slide 59 text

ABCDB: A Better Cool DataBase 1. Simple Micronaut application that pretends being a database product. 2. We want our customers to install it with a Kubernetes operator. • Instances will be created with a Custom Resource Definition 3. Packaged as a native executable inside a Docker image. 4. Can read configuration from a ConfigMap, and has a @Refreshable endpoint. 59 Copyright © 2024, Oracle and/or its affiliates

Slide 60

Slide 60 text

ABCDB Operator Deployed in the cluster, reconciles the state of the kind: AbcDb resources. 60 Copyright © 2024, Oracle and/or its affiliates

Slide 61

Slide 61 text

Copyright © 2024, Oracle and/or its affiliates 61 Q &A

Slide 62

Slide 62 text

Álvaro Sánchez-Mariscal @alvaro_sanchez

Slide 63

Slide 63 text

No content