SlideShare a Scribd company logo
The Operator Pattern
1
Managing Stateful Services in Kubernetes
Jakob Karalus, @krallistic
2
• Data Science + DevOps
• Codecentric
• CKA
• Twiiter: @krallistic
• Github: github.com/krallistic
$whoami
3
• Write some Deployment, Services, Configmaps etc
• Deploy them to K8s
• Maybe create a Helm Chart
Normal Kubernetes Deployment
4
Success?!
5
• Backups?
• Upscaling? Reshuffle Data?
• Downscaling? Without Dataloss?
• Healing? Restore Backups?
• Configuration? Tedious Templating?
But Day 2 Operations?
If only we could automate this!
6
In a Kubernetes native way!
7
Operators
Kubernetes
Apache Kafka
Operator
8
• Human Operational Software
• Custom Software
• Kubernetes Native:
• CustomResourceDefinition
• So lets write one:
Operators
• Defines a new API
• Seamless integration
with existing API
• Kubectl support
9
CustomResourceDefinition
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: crontabs.stable.example.com
spec:
group: stable.example.com
version: v1
scope: Namespaced
names:
plural: crontabs
singular: crontab
kind: CronTab
shortNames:
- ct
validation:
# openAPIV3Schema is the schema for validating
custom objects.
• Actual Object in new API
• No functionality.
10
CustomResourceDefinition
apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
name: my-new-cron-object
spec:
cronSpec: "* * * * */5"
image: my-awesome-cron-image
replicas: 5
11
• Operator create WATCH on
CR Objects
• Analyze difference Actual vs
Desired State
• Act on changes
Control Loop
Observe
Analyze
Act
Kafka Basics
12
Broker 0
Topic: “test”
Partitions: 4
Replicas: 2
Partition 0 – Replica 0
Partition 2 – Replica 1
Partition 3 – Replica 1
Broker 1 Broker 2
Partition 0 – Replica 1
Partition 1 – Replica 1
Partition 2 – Replica 0
Partition 1 – Replica 0
Partition 3 – Replica 0
Topic: “hello”
Partitions: 8
Replicas: 3
13
Create Cluster
Kind:
KafkaCluster
Name: analytics
Replicas: 3
ADD Event
Kind: ConfigMap
Name: kafka
Data: |
Kind: Statefulset
Name: analytics
Replicas: 3
Image: Kafka
POST
Create Pods
14
Downsize Cluster
Kind:
KafkaCluster
Name: analytics
Replicas: 2
Update Event
Desired:
Kind: Statefulset
Name: analytics
Replicas: 2
Image: Kafka
UPDATE
Current:
Kind: Statefulset
Name: analytics
Replicas: 3
Image: Kafka
Cluster
Rebalanced
Rebalance
Topic
Delete Pod
15
• Upsizing
• Live Rebalancing
• Updates
• Backups & Restores
• Failovers
Additional Usecases
16
• Extra Scheduling needs? -> Scheduler Extenders (Webhooks)
• More Advanced Scheduling Features -> Custom Schedulers
• Complex APIs beyond CRD -> Custom API Server with API Aggregation
• Control over what object can be created -> Admission Webhooks
• Control how objects should be initialized? -> Initializer
• Different Runtime needs? -> CRI, CNI
• Special Storage -> Flex Volumes, (CSI)
Not enough?
Elasticsearch Prometheus Postgres
17
Other Operators
18
• Helm itself a Operator (somewhat, working on it
https://github.com/kubernetes/helm/issues/3089) )
• Controllers
• Operator = Controller + CRD
• Operator = External Software
• Controller = Internal
• Only do operators if you cant solve it with Helm.
Operators vs Helm vs Controller
19
• WATCH for updates
• Generator Controller
• Informer
• Create API Spec
• Generate some Objects needed by Informer etc (Since 1.8)
• See: https://blog.openshift.com/kubernetes-deep-dive-code-generation-
customresources/ (Excellent, by sttts)
• Main
Code!
20
• Microservices, single Deployment
• Stateless, use CRD for States
• Operations should be Idempotent
• Leverage K8S Objects as most as possible
• CRD should be versioned, backwards compatible
Best Practice Operators
Questions? Discuss!
21
22
• Are we reinventing the Wheel?
• Mesos Frameworks?
• Nomad Custom Scheduler?
• Docker Swarm Plugins?
Take a step back
23
Custom Logic in Mesos
24
Task Mesos Kuberentes
Custom Resource Placement Write a framework Write a custom scheduler
Special resource init Write a framework Initializer
API access Every Framework has its own API Unified API
Special lifecyle Write a framework Kubernetes Operator
Custom execution Write a framework + executioner CRI Interface + Scheduler
Comparison

More Related Content

PPTX
Kubernetes @ meetic
PDF
Kubernetes One-Click Deployment: Hands-on Workshop (Munich)
PDF
(Draft) Kubernetes - A Comprehensive Overview
PPTX
Introduction to Kubernetes
PPTX
DevOps with Kubernetes
PDF
Evolution of containers to kubernetes
PPTX
Intro to cluster scheduler for Linux containers
PDF
Kubernetes - A Comprehensive Overview
Kubernetes @ meetic
Kubernetes One-Click Deployment: Hands-on Workshop (Munich)
(Draft) Kubernetes - A Comprehensive Overview
Introduction to Kubernetes
DevOps with Kubernetes
Evolution of containers to kubernetes
Intro to cluster scheduler for Linux containers
Kubernetes - A Comprehensive Overview

What's hot (20)

PDF
Hands-On Introduction to Kubernetes at LISA17
PDF
Kubernetes 101
PPTX
Service Discovery In Kubernetes
PDF
Kubernetes a comprehensive overview
PDF
Kubernetes Architecture - beyond a black box - Part 2
PDF
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
PDF
The (mutable) config management showdown
PDF
Kubernetes Requests and Limits
PDF
Kubernetes: The Next Research Platform
ODP
Kubernetes Architecture
PDF
Getting started with kubernetes
PDF
LISA2017 Kubernetes: Hit the Ground Running
PDF
Kubernetes intro public - kubernetes meetup 4-21-2015
PDF
WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...
PDF
Kubernetes 101
PDF
Deep Dive into Kubernetes - Part 1
PDF
Federated Kubernetes: As a Platform for Distributed Scientific Computing
PDF
What's new in Kubernetes
PDF
Kubernetes intro public - kubernetes user group 4-21-2015
Hands-On Introduction to Kubernetes at LISA17
Kubernetes 101
Service Discovery In Kubernetes
Kubernetes a comprehensive overview
Kubernetes Architecture - beyond a black box - Part 2
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
The (mutable) config management showdown
Kubernetes Requests and Limits
Kubernetes: The Next Research Platform
Kubernetes Architecture
Getting started with kubernetes
LISA2017 Kubernetes: Hit the Ground Running
Kubernetes intro public - kubernetes meetup 4-21-2015
WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...
Kubernetes 101
Deep Dive into Kubernetes - Part 1
Federated Kubernetes: As a Platform for Distributed Scientific Computing
What's new in Kubernetes
Kubernetes intro public - kubernetes user group 4-21-2015
Ad

Similar to The Operator Pattern - Managing Stateful Services in Kubernetes (20)

PDF
The Kubernetes Operator Pattern - ContainerConf Nov 2017
PDF
Managing Stateful Services with the Operator Pattern in Kubernetes - Kubernet...
PPTX
Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure F...
PPTX
Containers, Serverless and Functions in a nutshell
PPTX
Running Airflow Workflows as ETL Processes on Hadoop
PPTX
Running secured Spark job in Kubernetes compute cluster and integrating with ...
PPTX
Kubernetes Manchester - 6th December 2018
PPTX
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware
PPTX
A Million ways of Deploying a Kubernetes Cluster
PDF
Building scalbale cloud native apps with .NET 8
PDF
One Kubernetes to rule them all (ZEUS 2019 Keynote)
PDF
An intro to Kubernetes operators
PDF
DevOpsDays Houston 2019 - Shaun Ladewig, Robert Stone - From OverTheWallOps t...
PDF
Pro2516 10 things about oracle and k8s.pptx-final
PDF
Google Kubernetes Engine Deep Dive Meetup
PDF
[Spark Summit 2017 NA] Apache Spark on Kubernetes
PPTX
Adf with docker
PPTX
Centralizing Kubernetes and Container Operations
PDF
Kubernetes Architecture - beyond a black box - Part 1
PPTX
DevNexus 2015: Kubernetes & Container Engine
The Kubernetes Operator Pattern - ContainerConf Nov 2017
Managing Stateful Services with the Operator Pattern in Kubernetes - Kubernet...
Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure F...
Containers, Serverless and Functions in a nutshell
Running Airflow Workflows as ETL Processes on Hadoop
Running secured Spark job in Kubernetes compute cluster and integrating with ...
Kubernetes Manchester - 6th December 2018
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware
A Million ways of Deploying a Kubernetes Cluster
Building scalbale cloud native apps with .NET 8
One Kubernetes to rule them all (ZEUS 2019 Keynote)
An intro to Kubernetes operators
DevOpsDays Houston 2019 - Shaun Ladewig, Robert Stone - From OverTheWallOps t...
Pro2516 10 things about oracle and k8s.pptx-final
Google Kubernetes Engine Deep Dive Meetup
[Spark Summit 2017 NA] Apache Spark on Kubernetes
Adf with docker
Centralizing Kubernetes and Container Operations
Kubernetes Architecture - beyond a black box - Part 1
DevNexus 2015: Kubernetes & Container Engine
Ad

More from QAware GmbH (20)

PDF
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
PDF
Frontends mit Hilfe von KI entwickeln.pdf
PDF
Mit ChatGPT Dinosaurier besiegen - Möglichkeiten und Grenzen von LLM für die ...
PDF
50 Shades of K8s Autoscaling #JavaLand24.pdf
PDF
Make Agile Great - PM-Erfahrungen aus zwei virtuellen internationalen SAFe-Pr...
PPTX
Fully-managed Cloud-native Databases: The path to indefinite scale @ CNN Mainz
PDF
Down the Ivory Tower towards Agile Architecture
PDF
"Mixed" Scrum-Teams – Die richtige Mischung macht's!
PDF
Make Developers Fly: Principles for Platform Engineering
PDF
Der Tod der Testpyramide? – Frontend-Testing mit Playwright
PDF
Was kommt nach den SPAs
PDF
Cloud Migration mit KI: der Turbo
PDF
Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
PDF
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
PDF
Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.
PDF
Kubernetes with Cilium in AWS - Experience Report!
PDF
50 Shades of K8s Autoscaling
PDF
Kontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAP
PDF
Service Mesh Pain & Gain. Experiences from a client project.
PDF
50 Shades of K8s Autoscaling
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
Frontends mit Hilfe von KI entwickeln.pdf
Mit ChatGPT Dinosaurier besiegen - Möglichkeiten und Grenzen von LLM für die ...
50 Shades of K8s Autoscaling #JavaLand24.pdf
Make Agile Great - PM-Erfahrungen aus zwei virtuellen internationalen SAFe-Pr...
Fully-managed Cloud-native Databases: The path to indefinite scale @ CNN Mainz
Down the Ivory Tower towards Agile Architecture
"Mixed" Scrum-Teams – Die richtige Mischung macht's!
Make Developers Fly: Principles for Platform Engineering
Der Tod der Testpyramide? – Frontend-Testing mit Playwright
Was kommt nach den SPAs
Cloud Migration mit KI: der Turbo
Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.
Kubernetes with Cilium in AWS - Experience Report!
50 Shades of K8s Autoscaling
Kontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAP
Service Mesh Pain & Gain. Experiences from a client project.
50 Shades of K8s Autoscaling

Recently uploaded (20)

PPT
Reliability_Chapter_ presentation 1221.5784
PPTX
Moving the Public Sector (Government) to a Digital Adoption
PDF
Launch Your Data Science Career in Kochi – 2025
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PDF
Fluorescence-microscope_Botany_detailed content
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PDF
Foundation of Data Science unit number two notes
PPT
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
PPTX
1_Introduction to advance data techniques.pptx
PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
PDF
Clinical guidelines as a resource for EBP(1).pdf
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PDF
Mega Projects Data Mega Projects Data
PPTX
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
PPTX
Global journeys: estimating international migration
PPTX
Computer network topology notes for revision
Reliability_Chapter_ presentation 1221.5784
Moving the Public Sector (Government) to a Digital Adoption
Launch Your Data Science Career in Kochi – 2025
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Fluorescence-microscope_Botany_detailed content
IBA_Chapter_11_Slides_Final_Accessible.pptx
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
oil_refinery_comprehensive_20250804084928 (1).pptx
Foundation of Data Science unit number two notes
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
1_Introduction to advance data techniques.pptx
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
Clinical guidelines as a resource for EBP(1).pdf
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
Mega Projects Data Mega Projects Data
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
Global journeys: estimating international migration
Computer network topology notes for revision

The Operator Pattern - Managing Stateful Services in Kubernetes

  • 1. The Operator Pattern 1 Managing Stateful Services in Kubernetes Jakob Karalus, @krallistic
  • 2. 2 • Data Science + DevOps • Codecentric • CKA • Twiiter: @krallistic • Github: github.com/krallistic $whoami
  • 3. 3 • Write some Deployment, Services, Configmaps etc • Deploy them to K8s • Maybe create a Helm Chart Normal Kubernetes Deployment
  • 5. 5 • Backups? • Upscaling? Reshuffle Data? • Downscaling? Without Dataloss? • Healing? Restore Backups? • Configuration? Tedious Templating? But Day 2 Operations?
  • 6. If only we could automate this! 6 In a Kubernetes native way!
  • 8. 8 • Human Operational Software • Custom Software • Kubernetes Native: • CustomResourceDefinition • So lets write one: Operators
  • 9. • Defines a new API • Seamless integration with existing API • Kubectl support 9 CustomResourceDefinition apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: name: crontabs.stable.example.com spec: group: stable.example.com version: v1 scope: Namespaced names: plural: crontabs singular: crontab kind: CronTab shortNames: - ct validation: # openAPIV3Schema is the schema for validating custom objects.
  • 10. • Actual Object in new API • No functionality. 10 CustomResourceDefinition apiVersion: "stable.example.com/v1" kind: CronTab metadata: name: my-new-cron-object spec: cronSpec: "* * * * */5" image: my-awesome-cron-image replicas: 5
  • 11. 11 • Operator create WATCH on CR Objects • Analyze difference Actual vs Desired State • Act on changes Control Loop Observe Analyze Act
  • 12. Kafka Basics 12 Broker 0 Topic: “test” Partitions: 4 Replicas: 2 Partition 0 – Replica 0 Partition 2 – Replica 1 Partition 3 – Replica 1 Broker 1 Broker 2 Partition 0 – Replica 1 Partition 1 – Replica 1 Partition 2 – Replica 0 Partition 1 – Replica 0 Partition 3 – Replica 0 Topic: “hello” Partitions: 8 Replicas: 3
  • 13. 13 Create Cluster Kind: KafkaCluster Name: analytics Replicas: 3 ADD Event Kind: ConfigMap Name: kafka Data: | Kind: Statefulset Name: analytics Replicas: 3 Image: Kafka POST Create Pods
  • 14. 14 Downsize Cluster Kind: KafkaCluster Name: analytics Replicas: 2 Update Event Desired: Kind: Statefulset Name: analytics Replicas: 2 Image: Kafka UPDATE Current: Kind: Statefulset Name: analytics Replicas: 3 Image: Kafka Cluster Rebalanced Rebalance Topic Delete Pod
  • 15. 15 • Upsizing • Live Rebalancing • Updates • Backups & Restores • Failovers Additional Usecases
  • 16. 16 • Extra Scheduling needs? -> Scheduler Extenders (Webhooks) • More Advanced Scheduling Features -> Custom Schedulers • Complex APIs beyond CRD -> Custom API Server with API Aggregation • Control over what object can be created -> Admission Webhooks • Control how objects should be initialized? -> Initializer • Different Runtime needs? -> CRI, CNI • Special Storage -> Flex Volumes, (CSI) Not enough?
  • 18. 18 • Helm itself a Operator (somewhat, working on it https://github.com/kubernetes/helm/issues/3089) ) • Controllers • Operator = Controller + CRD • Operator = External Software • Controller = Internal • Only do operators if you cant solve it with Helm. Operators vs Helm vs Controller
  • 19. 19 • WATCH for updates • Generator Controller • Informer • Create API Spec • Generate some Objects needed by Informer etc (Since 1.8) • See: https://blog.openshift.com/kubernetes-deep-dive-code-generation- customresources/ (Excellent, by sttts) • Main Code!
  • 20. 20 • Microservices, single Deployment • Stateless, use CRD for States • Operations should be Idempotent • Leverage K8S Objects as most as possible • CRD should be versioned, backwards compatible Best Practice Operators
  • 22. 22 • Are we reinventing the Wheel? • Mesos Frameworks? • Nomad Custom Scheduler? • Docker Swarm Plugins? Take a step back
  • 24. 24 Task Mesos Kuberentes Custom Resource Placement Write a framework Write a custom scheduler Special resource init Write a framework Initializer API access Every Framework has its own API Unified API Special lifecyle Write a framework Kubernetes Operator Custom execution Write a framework + executioner CRI Interface + Scheduler Comparison