How to get started with Operators for Kubernetes

A presentation at Container Camp in May 2020 in by Max Körbächer

Slide 1

Slide 1

How to get started with Operators for Kubernetes Max Körbächer

Slide 2

Slide 2

Max Körbächer ● ● ● Happy Kuberneting anno 2016 Kubernetes Release Team since K8s v1.17 Manager Cloud Native Engineering @ Storm Reply

Slide 3

Slide 3

The way of how Kubernetes works Kubernetes is event driven Source: Michael Gasch

Slide 4

Slide 4

Running simple, stateless deployments Simple & Stateless? ● ● ● ● no long-run persistence needed can be shutdown “any time” can run multiple time without issues can run in different versions without issues “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” - C.A.R. Hoare

Slide 5

Slide 5

Running complex, stateful deployments aka DON’T TOUCH! ● ● ● ● Need stable persistency Can’t deal well with unpredictable issues Long(er) startup time Not flexible in scheduling What we are talking about? ● ● ● ● Databases Legacy migrations Architecture designs which can’t be event driven, stateless for some reasons Applications with many or heavy dependencies Such applications in a dynamic environment like K8s causes additional operational effort for Day2 and later.

Slide 6

Slide 6

Operators! A Kubernetes Operator abstracts the deployment of diverse and state sensitive applications by including domain-specific knowledge. ● ● ● ● Lifecycle Management Configuration Updates Handle Failures Operator are the result of translating operative knowledge, and developer-specific knowledge of an application into own software. Operator utilize Custom Resource Definitions (CRD) to extend natively the K8s resources and APIs. Long story short: software runs software

Slide 7

Slide 7

Capability Levels of Operator 5 Deep Insights Metrics, alerts & log processing and workload analysis 4 3 Seamless Upgrades Patch and minor release upgrades 2 1 Auto Pilot Horizontal scaling, auto config tuning, anomaly detection, scheduling optimization Full Lifecycle App lifecycle (automated canary deployments, rollbacks by failure, and so on), storage lifecycle (backup, failure recovery) Basic Install Automated application provisioning and configuration management

Slide 8

Slide 8

How does an Operator work? - Control(ler)/-loop Controllers act on core resources like deployments, statefulsets or service, but they also work with custom resources. Reque after error Notified about changes Controllers are implemented by a control loop: 1. 2. 3. Check state of resources, ideally by events Change state of the object or ext. resource Update status of the resource Independent of the complexity of your controller, in the end you will do always these steps. Controller Custom resource with a desired state Update status Adjust desired state K8s or Ext. world Important to note, but no time to go into depths: Informers, Work Queues & Events

Slide 9

Slide 9

How does an Operator work? - Operator Uses CRD CRD CRD Schema level Instance level Custom Controller Manages Custom resource with a desired state An operator sum up the operational knowledge of an SRE and their domain specific knowledge, to automate the common tasks. Custom Resource A Custom Resource Definition (CRD) captures the domain knowledge, while a custom resource represents this on an instance. Therefore a custom controller manages the custom resource by e.g. trigger a backup or start a new pod with a new software version.

Slide 10

Slide 10

Some options to get started Custom resource with a desired state Declarative/ Opinionated KUDO Or for the lazy people: Metacontroller Operator Framework/ SDK Flexible/ Open Kubebuilder

Slide 11

Slide 11

Some options to get started Custom resource with a desired state Declarative/ Opinionated KUDO Or for the lazy people: Metacontroller Operator Framework/ SDK Flexible/ Open Kubebuilder

Slide 12

Slide 12

Slide 13

Slide 13

Slide 14

Slide 14

Slide 15

Slide 15

Q&A