2. About me
● Attila Mészáros (csviri@gmail.com)
● 10+ years Java developer / architect
● Last 3 years more on platform teams
● Currently: Senior Software Engineer @
○ Building multi-cloud platform
○ Golang, K8S, AWS (on-prem, GCP, AZURE)
(Java) + Everything around
● Free Time
○ ❤Rust❤
○ co-creator of Java Operator SDK
3. Agenda
● Intro to Kubernetes Operators
● Simple Example
● Intro To Java Operator SDK
● Common problems and how we solve them
● Event Sources and the power of operators
4. Extending K8S API - CRDs
● Define Custom Type in K8S: Custom
Resource Defintion
● Abstraction over a more complex
domain
● Instance of our type we call Custom
Resource
● “kubectl apply” this =>
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: webservers.sample.javaoperatorsdk
spec:
group: sample.javaoperatorsdk
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
html:
type: string
scope: Namespaced
names:
plural: webservers
singular: webserver
kind: WebServer
shortNames:
- ws
6. Kubernetes Operator - Definition
● “Operators are software extensions to Kubernetes that make use of custom resources to
manage applications and their components. Operators follow Kubernetes principles, notably the
control loop.”
● That’s it, K8S does not provide any additional facilities. Only:
○ Extension to API - CRD/CR
○ and the operations we have on K8S Objects: CRUD, Patch, Watch
○ (ok for golang it kinda provides )
10. Managing K8S and non-K8S Resources
● Manage all well known K8S resources (pods, config maps, ingress, service, pv)
○ Create nice abstractions
○ Deploy/Manage Complex Applications (Kafka, Postgres)
○ Flux
● External Resources (or anything that has an API)
○ Git Repositories,
○ Users in external System
○ CockroachDB users
○ AWS Controllers for Kubernetes (ACK)
11. Framework Support
● Well known frameworks
○ Operator SDK (go, from RedHat)
○ Java Operator SDK
○ Kopf (python)
○ ...
12. History to Java Operator SDK
● Started on ~ May 2019
● Spinoff from a project on Java based big Enterprise Company
● From ~ 2020 November heavy RedHat involvement
● Now dedicated RedHat maintiners
● https://twitter.com/maxandersen/status/1387683489877831685
● Plugin to Operator SDK to generate Java Operator SDK project
● Interesting for big enterprises building heavily on Java
13. Why to use it?
● Why not just creating a watch?
● Fixes typical problem independent of programming language
● It’s a (micro)framework, so you have to just think about missing pieces.
○ Usually implementing a method
● Non trivial design issues
○ Like optimistic locking of status subresource?
14. Concurrency
● No concurrent event processing for same Custom Resource
● Correct handling of Optimistic Locking
15. Automatic Retries
● Network problems?
● Essential for correctness
● Configurable retries
○ Various backoff strategies
16. Finalizers
● Essential for correctness
● Automatically handled
● What if operator is down?
apiVersion: "sample.javaoperatorsdk/v1"
kind: WebServer
metadata:
name: hellows
finalizers:
- webservers.sample.javaoperatorsdk/finalizer
spec:
html: |
<html>
<head>
<title>Hello Operator World</title>
</head>
<body>
Hello Meetup
</body>
</html>
17. ...and more
● Support for Generations
● Nice API to update custom resource and/or status-subresource
● Integration with Quarkus and Spring Boot
● ...
20. How does it compare to Terraform
● With Terraform we provision resources managed by cloud providers
● With Operators we manage resources
○ (IMHO) But how it should be managed inside the controller implementation it’s quite
close to terraform
■ Status is state
■ Reconcile always all the resources independently from event
○ Note that some patterns are still just being explored.