kubernetes operators 101 - java2days · evolution of the operator pattern 28 you can have multiple...

54
Kubernetes Operators 101 Ali Ok Senior Software Engineer Red Hat 1 http://bit.ly/operators-101

Upload: others

Post on 17-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Kubernetes Operators 101

Ali OkSenior Software Engineer Red Hat

1

http://bit.ly/operators-101

Page 2: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

2

About meSenior Software Engineer @ Red Hat

Knative Eventing Team

Remotee in Istanbul

Page 3: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Operators

3

Page 4: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

AGENDA

4

First show some stuff

Then explain why we need all of these with use cases

Compare to other approaches

Agenda

Page 5: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

AGENDA

5

Kubernetes resources

Step back

Page 6: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Kubernetes resources

6

Kubernetes resources

Replicas

et

Pod#1

Pod#2

Page 7: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Kubernetes resources

7

Page 8: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Kubernetes resources

8

Kubernetes resources

Page 9: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Custom resources

9

What if Kubernetes would understand custom resources like a definition of a Postgres cluster?

Custom resources

Page 10: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Custom resources

10

Page 11: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Custom resource definition

11

Page 12: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Custom resource definition

12

Page 13: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Custom resources

13

Ok, we have the custom resource there, but now what?

It is not going to create actual Postgres instances itself!

...

Page 14: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Custom resources

14

Reconciliation

Page 15: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

15

Simple application that uses Kubernetes REST api to create/update/delete Postgres instances

Basic Operator

Page 16: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

16

Basic Operator

Page 17: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

17

… it is awful to use unstructured data, especially in a strongly typed language

Ok, but ...

Page 18: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

18

Let’s create types for the CRDs and make the REST client use them

Types for the CRDs

Page 19: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

19

Types for the CRDs

Page 20: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

20

Typed REST client usage

Page 21: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

21

… it is awful to define and register these types manually and also do the REST client configuration

Ok, but ...

Page 22: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

22

Let’s generate code for the CRDs and also register them

Code generation for the CRDs

Page 23: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

23

Code generation for the CRDs

Page 24: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

24

will generate CRD yaml file to feed to Kubernetes, as well as a typed REST clientset

Code generation for the CRDs

Page 25: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

25

Code generation for the CRDs

Page 26: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

26

Watch instead of poll

Page 27: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

27

Let the informer filter the events for you

...

Informers for better eventing model

Page 28: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

28

You can have multiple controllers where you want to be informed about the same set of resources

Especially secondary resources

Shared informers

Page 29: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

29

Retries

Rate limiting

Work queues

Page 30: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

30

Ability to horizontally scale the operator

Leader election

Page 31: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Evolution of the operator pattern

31

...

More and more stuff

Page 32: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Operator SDK

32

All of the steps are provided for you

CLI to do code generation and scaffolding

High level API and abstraction

Enter Operator SDK

Page 33: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Operator SDK

33

A particular opinionated way to implement operators

Best practices are included

No need to be a Kubernetes / Golang expert

Enter Operator SDK

Page 34: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Demo

34

DEMO TIME!

https://github.com/aliok/postgres-operator-complete

Demo

Page 35: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Operator Framework

35

SDK + CLI

Operator Lifecycle Manager (OLM)

OperatorHub

Operator Metering

Operator Framework

Page 36: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

OperatorHub

36

Marketplace for Operators

OperatorHub

Page 37: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

OperatorHub

37

Page 38: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

OperatorHub

38

Page 39: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Operator maturity model

39

Operator maturity model

Page 40: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

OLM

40

Operators that manage your operators

Some level of dependency resolution

Upgrades

Enabling users to use services

OLM

Page 41: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

AGENDA

41

First show some stuff

Then explain why we need all of these with use cases

Compare to other approaches

Agenda

Page 42: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Human operators vs software operators

42

Target is automating the software operating!

Human operators vs software operators

Page 43: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Use cases

43

Installing stuff

State preservation

Managed software

Stateful apps

Use cases

Page 44: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Real world operators

44

Real world operator - Postgres DB creation

Page 45: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Real world operators

45

Real world operator - Keycloak realm creation in existing server

Page 46: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Real world operators

46

Real world operator - Grafana dashboard creation in existing service

Page 47: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Real world operators

47

Real world operators - OpenShift

Operator that handles network config

Operator that handles web console

Operator that handles authorization

Page 48: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Comparison to other operator building tools

48

Kubebuilder and Operator SDK converge

Now, both use controller-runtime and controller-tools

Conversion from one to another is easy

Compare: kubebuilder

Page 49: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Comparison to other operator building tools

49

Operator SDK has support for Operator Framework features

More:

github.com/operator-framework/operator-sdk/issues/1758

Compare: kubebuilder

Page 50: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Comparison to other operator building tools

50

Complete abstraction of machinery

Webhook based and you can use any language you like

Not flexible enough, but can be sufficient in some use cases

Compare: Metacontroller

Page 51: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Ansible, Helm, Java

51

Operator Framework also supports Ansible and Helm operators

If you have existing Ansible playbooks or Helm charts, you can wrap them in an operator

There are some Java Operator SDKs which can be sufficient in some cases

Ansible, Helm, Java

Page 52: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Summary

52

Make use of operators to use other people's expertise in operating the dependencies

Write your own operator to operate your software

Summary

Page 53: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Final words

53

Not specific to OpenShift!

No need to be an expert in Golang

kube-builder and Operator SDK converging

Awesome operators: github.com/operator-framework/awesome-operators

learn.openshift.com/operatorframework

Final words

Page 54: Kubernetes Operators 101 - Java2Days · Evolution of the operator pattern 28 You can have multiple controllers where you want to be informed about the same set of resources ... Ansible,

Twitter - @aliok_tr

Github - aliok

Thank you

54