KEMBAR78
Intro to creating kubernetes operators | PDF
Intro to Creating
Kubernetes
Operators
... and what can a framework do for you
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
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
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
Sample Custom Resource
apiVersion: "sample.javaoperatorsdk/v1"
kind: WebServer
metadata:
name: hellows
spec:
html: |
<html>
<head>
<title>Hello Operator World</title>
</head>
<body>
Hello Meetup
</body>
</html>
● simple examples: abstraction over
static website
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 )
What is a control loop?
The Operator Pattern
● At the end it’s a Pod watching
Custom Resources
● and Reconciling the desired state
with the target world
Demo Time - WebServer Example
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)
Framework Support
● Well known frameworks
○ Operator SDK (go, from RedHat)
○ Java Operator SDK
○ Kopf (python)
○ ...
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
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?
Concurrency
● No concurrent event processing for same Custom Resource
● Correct handling of Optimistic Locking
Automatic Retries
● Network problems?
● Essential for correctness
● Configurable retries
○ Various backoff strategies
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>
...and more
● Support for Generations
● Nice API to update custom resource and/or status-subresource
● Integration with Quarkus and Spring Boot
● ...
Event Sources - Dependent Resources
Event Sources
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.
Thank you!
Time for Questions!

Intro to creating kubernetes operators

  • 1.
    Intro to Creating Kubernetes Operators ...and what can a framework do for you
  • 2.
    About me ● AttilaMé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 toKubernetes 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
  • 5.
    Sample Custom Resource apiVersion:"sample.javaoperatorsdk/v1" kind: WebServer metadata: name: hellows spec: html: | <html> <head> <title>Hello Operator World</title> </head> <body> Hello Meetup </body> </html> ● simple examples: abstraction over static website
  • 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 )
  • 7.
    What is acontrol loop?
  • 8.
    The Operator Pattern ●At the end it’s a Pod watching Custom Resources ● and Reconciling the desired state with the target world
  • 9.
    Demo Time -WebServer Example
  • 10.
    Managing K8S andnon-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 ● Wellknown frameworks ○ Operator SDK (go, from RedHat) ○ Java Operator SDK ○ Kopf (python) ○ ...
  • 12.
    History to JavaOperator 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 useit? ● 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 concurrentevent processing for same Custom Resource ● Correct handling of Optimistic Locking
  • 15.
    Automatic Retries ● Networkproblems? ● Essential for correctness ● Configurable retries ○ Various backoff strategies
  • 16.
    Finalizers ● Essential forcorrectness ● 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 ● Supportfor Generations ● Nice API to update custom resource and/or status-subresource ● Integration with Quarkus and Spring Boot ● ...
  • 18.
    Event Sources -Dependent Resources
  • 19.
  • 20.
    How does itcompare 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.
  • 21.