SlideShare una empresa de Scribd logo
1 de 15
Kubernetes Operators
Nov 2018Iris Team
With Scala
About Me
Bill
Javier
Peter Barron
Principal Engineer
IRIS
Conor
Located in Dublin,
IRIS is a technical
unit in Zalando that
is focused on ML and
Data Intensive
Systems.
What is an Operator?
“An Operator is a method of packaging,
deploying and managing a Kubernetes
application.” [1]
“Conceptually, an Operator takes human
operational knowledge and encodes it
into software that is more easily packaged
and shared with consumers.” [1]
[1] https://coreos.com/operators
[2] https://github.com/operator-framework/awesome-operators
Custom Resource Definitions
[1] https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: predictiondeployments.zalando.org
spec:
additionalPrinterColumns:
- JSONPath: .spec.scope
name: Scope
type: string
- JSONPath: .status.phase
name: Phase
type: string
- JSONPath: .metadata.creationTimestamp
description: Age of the stack
name: Age
type: date
group: zalando.org
version: v1alpha1
scope: Namespaced
names:
plural: predictiondeployments
singular: predictiondeployment
kind: PredictionDeployment
shortNames:
- pd
categories:
- all
validation:
openAPIV3Schema:
properties:
spec:
properties:
scope:
type: string
….
subresources:
status: {}
How does an Operator work?
Kind: KafkaCluster
Replicas: 2
…
So how do you build an
Operator in Scala?
Basic Building Block
implicit val system: ActorSystem = ActorSystem("Operator")
implicit val mat: ActorMaterializer = ActorMaterializer()
implicit val ec: ExecutionContext = system.dispatcher
val k8s: client.RequestContext = k8sInit
val stream: Future[(UniqueKillSwitch, Future[Done])] =
k8s.list[PredictionDeployment].map { l =>
k8s.watchAllContinuously[PredictionDeployment](Some(l.resourceVersion))
.viaMat(KillSwitches.single)(Keep.right)
.groupBy(10, we => we._object.name)
.map{ we =>
we._type match {
case ADDED => reconcile(we)
case MODIFIED => reconcile(we)
case DELETED => we
case ERROR => we
}
}.async.mergeSubstreams
.toMat(Sink.ignore)(Keep.both)
.run()
}
Determine
starting point
Create a Akka
Stream Source of
watch events
Process events
SKUBER
Create Sub Streams to
process in parallel
On Startup - Committer
implicit val system: ActorSystem = ActorSystem("Operator")
implicit val mat: ActorMaterializer = ActorMaterializer()
implicit val ec: ExecutionContext = system.dispatcher
val streamId = StreamId("pd")
val k8s: client.RequestContext = k8sInit
val committer: Committer = buildCommiter()
val stream = committer.retrieve[PredictionDeployment](streamId,Position.Latest).map(offset =>
k8s.watchAllContinuously[PredictionDeployment](offset)
.viaMat(KillSwitches.single)(Keep.right)
.groupBy(10, we => we._object.name)
.map { we =>
we._type match {
case ADDED => reconcile(we)
case MODIFIED => reconcile(we)
case DELETED => we
case ERROR => we
}
}.async.mergeSubstreams.map { we =>
committer.commit(streamId, Offset(we._object.metadata.resourceVersion))
}.toMat(Sink.ignore)(Keep.both) .run()
)
Create Kafka like
committer
Retrieve offset,
defaulting to latest
position is non exist
Commit offset
On Startup - Alternative
implicit val system: ActorSystem = ActorSystem("Operator")
implicit val mat: ActorMaterializer = ActorMaterializer()
implicit val ec: ExecutionContext = system.dispatcher
val k8s: client.RequestContext = k8sInit
val stream= k8s.list[PredictionDeploymentList].map { l =>
Source(l.items.map(l => WatchEvent(MODIFIED, l))).concat(
k8s.watchAllContinuously[PredictionDeployment](Some(l.resourceVersion))
).viaMat(KillSwitches.single)(Keep.right)
.groupBy(10, we => we._object.name)
.map { we =>
we._type match {
case ADDED => reconcile(we)
case MODIFIED => reconcile(we)
case DELETED => we
case ERROR => we
}
}.async.mergeSubstreams
.toMat(Sink.ignore)(Keep.both).run()
}
Retrieve current state of
Prediction Deployment
resources.
Use the resource version
from the list operator to
subsequent changes
Reconciling
The reconciler function ensures that
the state of the system matches the
specification defined by the resource.
Derive
Expected
State
Determine
Current
State
Calculate
Difference
Apply
changes
Reconciling
EitherT(
k8s.create[O](resource).map(Right(_)).recoverWith {
case ex: K8SException if ex.status.code.contains(409) =>
k8s.get[O](resource.name).flatMap { existing =>
if (existing.metadata.ownerReferences.contains(ORef(pd))) {
if (!resource.subsetOf(existing)) {
k8s.update[O](existing.merge(resource))
.map(Right(_))
.recoverWith(K8sErrorHandler())
} else {
Future.successful(Right(existing))
}
} else {
Future.successful(Left(DuplicateService))
}
}
}.recoverWith(
K8sErrorHandler()
)
)
}
Optimistically attempt to
create the resource.
If that fails resolve the
conflict and update if
necessary
Subset is an implicit
function that determines
if the resource needs to
be updated.
Merge is an implicit
function that combines
the resources.
Working with Multiple Resource Types
val pdSource = k8s.list[PredictionDeploymentList].map { l =>
Source(l.items.map(l => WatchEvent(MODIFIED, l))).concat(
k8s.watchAllContinuously[PredictionDeployment](Some(l.resourceVersion))
)
}
val dSource = k8s.list[DeploymentList].map { l =>
k8s.watchAllContinuously[Deployment](Some(l.resourceVersion))
}
Future.sequence(List(pdSource, dSource)).map(s =>
Source.combine(s.head, s(1))(Merge(_))
.viaMat(KillSwitches.single)(Keep.right)
.groupBy(10, we => we._object.name)
.map {
case `WatchEvent[PredictionDeployment]`(we) => we
case `WatchEvent[Deployment]`(we) => we
}.async.mergeSubstreams
.toMat(Sink.ignore)(Keep.both).run()
)
Combine sources into a
single source
Use shapeless ‘TypeCase’
to avoid type erasure
Demo
Demo - Outline
Package
Deploy
Publish
Questions

Más contenido relacionado

La actualidad más candente

Architecting Alive Apps
Architecting Alive AppsArchitecting Alive Apps
Architecting Alive AppsJorge Ortiz
 
OpenStack Horizon: Controlling the Cloud using Django
OpenStack Horizon: Controlling the Cloud using DjangoOpenStack Horizon: Controlling the Cloud using Django
OpenStack Horizon: Controlling the Cloud using DjangoDavid Lapsley
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on AndroidTomáš Kypta
 
Scala.js: Next generation front end development in Scala
Scala.js:  Next generation front end development in ScalaScala.js:  Next generation front end development in Scala
Scala.js: Next generation front end development in ScalaOtto Chrons
 
Building Serverless Data Infrastructure in the AWS Cloud
Building Serverless Data Infrastructure in the AWS CloudBuilding Serverless Data Infrastructure in the AWS Cloud
Building Serverless Data Infrastructure in the AWS CloudRyan Plant
 
Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018
Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018
Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018Chris Gillum
 
Building a Lambda Architecture with Elasticsearch at Yieldbot
Building a Lambda Architecture with Elasticsearch at YieldbotBuilding a Lambda Architecture with Elasticsearch at Yieldbot
Building a Lambda Architecture with Elasticsearch at Yieldbotyieldbot
 
Inside Azure Diagnostics
Inside Azure DiagnosticsInside Azure Diagnostics
Inside Azure DiagnosticsMichael Collier
 
Redux. From twitter hype to production
Redux. From twitter hype to productionRedux. From twitter hype to production
Redux. From twitter hype to productionFDConf
 
Introducing Athena: 08/19 Big Data Application Meetup, Talk #3
Introducing Athena: 08/19 Big Data Application Meetup, Talk #3 Introducing Athena: 08/19 Big Data Application Meetup, Talk #3
Introducing Athena: 08/19 Big Data Application Meetup, Talk #3 Cask Data
 
Developing a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and SprayDeveloping a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and SprayJacob Park
 
Making connected apps with BaaS (Droidcon Bangalore 2014)
Making connected apps with BaaS (Droidcon Bangalore 2014)Making connected apps with BaaS (Droidcon Bangalore 2014)
Making connected apps with BaaS (Droidcon Bangalore 2014)Varun Torka
 
Programming Azure Active Directory (DevLink 2014)
Programming Azure Active Directory (DevLink 2014)Programming Azure Active Directory (DevLink 2014)
Programming Azure Active Directory (DevLink 2014)Michael Collier
 
A dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioA dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioGioia Ballin
 
«От экспериментов с инфраструктурой до внедрения в продакшен»​
«От экспериментов с инфраструктурой до внедрения в продакшен»​«От экспериментов с инфраструктурой до внедрения в продакшен»​
«От экспериментов с инфраструктурой до внедрения в продакшен»​FDConf
 
Icinga2 api use cases
Icinga2 api use casesIcinga2 api use cases
Icinga2 api use casesroy peter
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...smn-automate
 
Beyond Profilers: Tracing Node.js Transactions
Beyond Profilers: Tracing Node.js TransactionsBeyond Profilers: Tracing Node.js Transactions
Beyond Profilers: Tracing Node.js TransactionsTerral R Jordan
 
Closing the Loop in Extended Reality with Kafka Streams and Machine Learning ...
Closing the Loop in Extended Reality with Kafka Streams and Machine Learning ...Closing the Loop in Extended Reality with Kafka Streams and Machine Learning ...
Closing the Loop in Extended Reality with Kafka Streams and Machine Learning ...confluent
 

La actualidad más candente (20)

Architecting Alive Apps
Architecting Alive AppsArchitecting Alive Apps
Architecting Alive Apps
 
OpenStack Horizon: Controlling the Cloud using Django
OpenStack Horizon: Controlling the Cloud using DjangoOpenStack Horizon: Controlling the Cloud using Django
OpenStack Horizon: Controlling the Cloud using Django
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Scala.js: Next generation front end development in Scala
Scala.js:  Next generation front end development in ScalaScala.js:  Next generation front end development in Scala
Scala.js: Next generation front end development in Scala
 
Building Serverless Data Infrastructure in the AWS Cloud
Building Serverless Data Infrastructure in the AWS CloudBuilding Serverless Data Infrastructure in the AWS Cloud
Building Serverless Data Infrastructure in the AWS Cloud
 
Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018
Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018
Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018
 
Building a Lambda Architecture with Elasticsearch at Yieldbot
Building a Lambda Architecture with Elasticsearch at YieldbotBuilding a Lambda Architecture with Elasticsearch at Yieldbot
Building a Lambda Architecture with Elasticsearch at Yieldbot
 
Inside Azure Diagnostics
Inside Azure DiagnosticsInside Azure Diagnostics
Inside Azure Diagnostics
 
Redux. From twitter hype to production
Redux. From twitter hype to productionRedux. From twitter hype to production
Redux. From twitter hype to production
 
Introducing Athena: 08/19 Big Data Application Meetup, Talk #3
Introducing Athena: 08/19 Big Data Application Meetup, Talk #3 Introducing Athena: 08/19 Big Data Application Meetup, Talk #3
Introducing Athena: 08/19 Big Data Application Meetup, Talk #3
 
Developing a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and SprayDeveloping a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and Spray
 
Making connected apps with BaaS (Droidcon Bangalore 2014)
Making connected apps with BaaS (Droidcon Bangalore 2014)Making connected apps with BaaS (Droidcon Bangalore 2014)
Making connected apps with BaaS (Droidcon Bangalore 2014)
 
Programming Azure Active Directory (DevLink 2014)
Programming Azure Active Directory (DevLink 2014)Programming Azure Active Directory (DevLink 2014)
Programming Azure Active Directory (DevLink 2014)
 
A dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioA dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenario
 
«От экспериментов с инфраструктурой до внедрения в продакшен»​
«От экспериментов с инфраструктурой до внедрения в продакшен»​«От экспериментов с инфраструктурой до внедрения в продакшен»​
«От экспериментов с инфраструктурой до внедрения в продакшен»​
 
Icinga2 api use cases
Icinga2 api use casesIcinga2 api use cases
Icinga2 api use cases
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
 
Beyond Profilers: Tracing Node.js Transactions
Beyond Profilers: Tracing Node.js TransactionsBeyond Profilers: Tracing Node.js Transactions
Beyond Profilers: Tracing Node.js Transactions
 
Closing the Loop in Extended Reality with Kafka Streams and Machine Learning ...
Closing the Loop in Extended Reality with Kafka Streams and Machine Learning ...Closing the Loop in Extended Reality with Kafka Streams and Machine Learning ...
Closing the Loop in Extended Reality with Kafka Streams and Machine Learning ...
 
Intro to sbt-web
Intro to sbt-webIntro to sbt-web
Intro to sbt-web
 

Similar a Kubernetes Operators With Scala

DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your TeamGR8Conf
 
Decompose the monolith into AWS Step Functions
Decompose the monolith into AWS Step FunctionsDecompose the monolith into AWS Step Functions
Decompose the monolith into AWS Step FunctionsbeSharp
 
Akka lsug skills matter
Akka lsug skills matterAkka lsug skills matter
Akka lsug skills matterSkills Matter
 
Scaling Web Apps with Akka
Scaling Web Apps with AkkaScaling Web Apps with Akka
Scaling Web Apps with AkkaMaciej Matyjas
 
Habitat & Amazon's ECS
Habitat & Amazon's ECSHabitat & Amazon's ECS
Habitat & Amazon's ECSMatt Ray
 
Red Hat OpenShift Operators - Operators ABC
Red Hat OpenShift Operators - Operators ABCRed Hat OpenShift Operators - Operators ABC
Red Hat OpenShift Operators - Operators ABCRobert Bohne
 
Online Meetup: Why should container system / platform builders care about con...
Online Meetup: Why should container system / platform builders care about con...Online Meetup: Why should container system / platform builders care about con...
Online Meetup: Why should container system / platform builders care about con...Docker, Inc.
 
Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Luca Lusso
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesLindsay Holmwood
 
Docker Online Meetup: Infrakit update and Q&A
Docker Online Meetup: Infrakit update and Q&ADocker Online Meetup: Infrakit update and Q&A
Docker Online Meetup: Infrakit update and Q&ADocker, Inc.
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsInfrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsMykyta Protsenko
 
Productionalizing spark streaming applications
Productionalizing spark streaming applicationsProductionalizing spark streaming applications
Productionalizing spark streaming applicationsRobert Sanders
 
Scalable and Fault-Tolerant Apps with AWS
Scalable and Fault-Tolerant Apps with AWSScalable and Fault-Tolerant Apps with AWS
Scalable and Fault-Tolerant Apps with AWSFernando Rodriguez
 
Altitude SF 2017: Nomad and next-gen application architectures
Altitude SF 2017: Nomad and next-gen application architecturesAltitude SF 2017: Nomad and next-gen application architectures
Altitude SF 2017: Nomad and next-gen application architecturesFastly
 
Building Stateful Microservices With Akka
Building Stateful Microservices With AkkaBuilding Stateful Microservices With Akka
Building Stateful Microservices With AkkaYaroslav Tkachenko
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade ServerlessKatyShimizu
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade ServerlessKatyShimizu
 
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptxTrack 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptxAmazon Web Services
 
apidays LIVE Australia - Building distributed systems on the shoulders of gia...
apidays LIVE Australia - Building distributed systems on the shoulders of gia...apidays LIVE Australia - Building distributed systems on the shoulders of gia...
apidays LIVE Australia - Building distributed systems on the shoulders of gia...apidays
 
Azure Durable Functions (2018-06-13)
Azure Durable Functions (2018-06-13)Azure Durable Functions (2018-06-13)
Azure Durable Functions (2018-06-13)Paco de la Cruz
 

Similar a Kubernetes Operators With Scala (20)

DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your Team
 
Decompose the monolith into AWS Step Functions
Decompose the monolith into AWS Step FunctionsDecompose the monolith into AWS Step Functions
Decompose the monolith into AWS Step Functions
 
Akka lsug skills matter
Akka lsug skills matterAkka lsug skills matter
Akka lsug skills matter
 
Scaling Web Apps with Akka
Scaling Web Apps with AkkaScaling Web Apps with Akka
Scaling Web Apps with Akka
 
Habitat & Amazon's ECS
Habitat & Amazon's ECSHabitat & Amazon's ECS
Habitat & Amazon's ECS
 
Red Hat OpenShift Operators - Operators ABC
Red Hat OpenShift Operators - Operators ABCRed Hat OpenShift Operators - Operators ABC
Red Hat OpenShift Operators - Operators ABC
 
Online Meetup: Why should container system / platform builders care about con...
Online Meetup: Why should container system / platform builders care about con...Online Meetup: Why should container system / platform builders care about con...
Online Meetup: Why should container system / platform builders care about con...
 
Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
Docker Online Meetup: Infrakit update and Q&A
Docker Online Meetup: Infrakit update and Q&ADocker Online Meetup: Infrakit update and Q&A
Docker Online Meetup: Infrakit update and Q&A
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsInfrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and Ops
 
Productionalizing spark streaming applications
Productionalizing spark streaming applicationsProductionalizing spark streaming applications
Productionalizing spark streaming applications
 
Scalable and Fault-Tolerant Apps with AWS
Scalable and Fault-Tolerant Apps with AWSScalable and Fault-Tolerant Apps with AWS
Scalable and Fault-Tolerant Apps with AWS
 
Altitude SF 2017: Nomad and next-gen application architectures
Altitude SF 2017: Nomad and next-gen application architecturesAltitude SF 2017: Nomad and next-gen application architectures
Altitude SF 2017: Nomad and next-gen application architectures
 
Building Stateful Microservices With Akka
Building Stateful Microservices With AkkaBuilding Stateful Microservices With Akka
Building Stateful Microservices With Akka
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptxTrack 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
 
apidays LIVE Australia - Building distributed systems on the shoulders of gia...
apidays LIVE Australia - Building distributed systems on the shoulders of gia...apidays LIVE Australia - Building distributed systems on the shoulders of gia...
apidays LIVE Australia - Building distributed systems on the shoulders of gia...
 
Azure Durable Functions (2018-06-13)
Azure Durable Functions (2018-06-13)Azure Durable Functions (2018-06-13)
Azure Durable Functions (2018-06-13)
 

Último

Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 

Último (20)

Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 

Kubernetes Operators With Scala

  • 2. About Me Bill Javier Peter Barron Principal Engineer IRIS Conor Located in Dublin, IRIS is a technical unit in Zalando that is focused on ML and Data Intensive Systems.
  • 3. What is an Operator? “An Operator is a method of packaging, deploying and managing a Kubernetes application.” [1] “Conceptually, an Operator takes human operational knowledge and encodes it into software that is more easily packaged and shared with consumers.” [1] [1] https://coreos.com/operators [2] https://github.com/operator-framework/awesome-operators
  • 4. Custom Resource Definitions [1] https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: name: predictiondeployments.zalando.org spec: additionalPrinterColumns: - JSONPath: .spec.scope name: Scope type: string - JSONPath: .status.phase name: Phase type: string - JSONPath: .metadata.creationTimestamp description: Age of the stack name: Age type: date group: zalando.org version: v1alpha1 scope: Namespaced names: plural: predictiondeployments singular: predictiondeployment kind: PredictionDeployment shortNames: - pd categories: - all validation: openAPIV3Schema: properties: spec: properties: scope: type: string …. subresources: status: {}
  • 5. How does an Operator work? Kind: KafkaCluster Replicas: 2 …
  • 6. So how do you build an Operator in Scala?
  • 7. Basic Building Block implicit val system: ActorSystem = ActorSystem("Operator") implicit val mat: ActorMaterializer = ActorMaterializer() implicit val ec: ExecutionContext = system.dispatcher val k8s: client.RequestContext = k8sInit val stream: Future[(UniqueKillSwitch, Future[Done])] = k8s.list[PredictionDeployment].map { l => k8s.watchAllContinuously[PredictionDeployment](Some(l.resourceVersion)) .viaMat(KillSwitches.single)(Keep.right) .groupBy(10, we => we._object.name) .map{ we => we._type match { case ADDED => reconcile(we) case MODIFIED => reconcile(we) case DELETED => we case ERROR => we } }.async.mergeSubstreams .toMat(Sink.ignore)(Keep.both) .run() } Determine starting point Create a Akka Stream Source of watch events Process events SKUBER Create Sub Streams to process in parallel
  • 8. On Startup - Committer implicit val system: ActorSystem = ActorSystem("Operator") implicit val mat: ActorMaterializer = ActorMaterializer() implicit val ec: ExecutionContext = system.dispatcher val streamId = StreamId("pd") val k8s: client.RequestContext = k8sInit val committer: Committer = buildCommiter() val stream = committer.retrieve[PredictionDeployment](streamId,Position.Latest).map(offset => k8s.watchAllContinuously[PredictionDeployment](offset) .viaMat(KillSwitches.single)(Keep.right) .groupBy(10, we => we._object.name) .map { we => we._type match { case ADDED => reconcile(we) case MODIFIED => reconcile(we) case DELETED => we case ERROR => we } }.async.mergeSubstreams.map { we => committer.commit(streamId, Offset(we._object.metadata.resourceVersion)) }.toMat(Sink.ignore)(Keep.both) .run() ) Create Kafka like committer Retrieve offset, defaulting to latest position is non exist Commit offset
  • 9. On Startup - Alternative implicit val system: ActorSystem = ActorSystem("Operator") implicit val mat: ActorMaterializer = ActorMaterializer() implicit val ec: ExecutionContext = system.dispatcher val k8s: client.RequestContext = k8sInit val stream= k8s.list[PredictionDeploymentList].map { l => Source(l.items.map(l => WatchEvent(MODIFIED, l))).concat( k8s.watchAllContinuously[PredictionDeployment](Some(l.resourceVersion)) ).viaMat(KillSwitches.single)(Keep.right) .groupBy(10, we => we._object.name) .map { we => we._type match { case ADDED => reconcile(we) case MODIFIED => reconcile(we) case DELETED => we case ERROR => we } }.async.mergeSubstreams .toMat(Sink.ignore)(Keep.both).run() } Retrieve current state of Prediction Deployment resources. Use the resource version from the list operator to subsequent changes
  • 10. Reconciling The reconciler function ensures that the state of the system matches the specification defined by the resource. Derive Expected State Determine Current State Calculate Difference Apply changes
  • 11. Reconciling EitherT( k8s.create[O](resource).map(Right(_)).recoverWith { case ex: K8SException if ex.status.code.contains(409) => k8s.get[O](resource.name).flatMap { existing => if (existing.metadata.ownerReferences.contains(ORef(pd))) { if (!resource.subsetOf(existing)) { k8s.update[O](existing.merge(resource)) .map(Right(_)) .recoverWith(K8sErrorHandler()) } else { Future.successful(Right(existing)) } } else { Future.successful(Left(DuplicateService)) } } }.recoverWith( K8sErrorHandler() ) ) } Optimistically attempt to create the resource. If that fails resolve the conflict and update if necessary Subset is an implicit function that determines if the resource needs to be updated. Merge is an implicit function that combines the resources.
  • 12. Working with Multiple Resource Types val pdSource = k8s.list[PredictionDeploymentList].map { l => Source(l.items.map(l => WatchEvent(MODIFIED, l))).concat( k8s.watchAllContinuously[PredictionDeployment](Some(l.resourceVersion)) ) } val dSource = k8s.list[DeploymentList].map { l => k8s.watchAllContinuously[Deployment](Some(l.resourceVersion)) } Future.sequence(List(pdSource, dSource)).map(s => Source.combine(s.head, s(1))(Merge(_)) .viaMat(KillSwitches.single)(Keep.right) .groupBy(10, we => we._object.name) .map { case `WatchEvent[PredictionDeployment]`(we) => we case `WatchEvent[Deployment]`(we) => we }.async.mergeSubstreams .toMat(Sink.ignore)(Keep.both).run() ) Combine sources into a single source Use shapeless ‘TypeCase’ to avoid type erasure
  • 13. Demo

Notas del editor

  1. Who am I? Peter Barron Principal Engineer @Zalando Where do i work? What Team am I part of? What we are doing. We are looking at build infrastructure for ML In particular we are currently focused on the serving aspect of delivering ML models to production. Nearly all of the infrastructure we are currently building is built on kubernetes and as such we are looking to build on that foundation
  2. Who initially can up with the idea? What is an operator? For the most part K8s can handle the deployment service… Point of extensibilty What problem is being solved? What do that do? Installation Upgrades Lifecycle Auto-pilot What type applications use Operators Stateful applications such as Kafka Argo - native workflows, events, CI and CD Kubeless - lambda for k8s
  3. This is an example of CRD. Provides extensibility for k8s Describes a custom resource. Skuber provides support for building CRDs.
  4. An operator processes and acts on a stream of events from K8s. Depending on the events an operator Create/Update/remove/delete the resources in K8s Can interact with the deployed artifacts - in this case rebalance a topic. Other third party components - Monitoring etc.. Concepts to get across Scala is a good fit… particularly reactive frameworks such as akka and akka streams
  5. Why are we doing this? Scala is the dominant language within the team/office. There enough scala library support to process streams of events. Need to able to two things: Process a stream of watch events from the K8s cluster. Act Update/Create/Remove a K8s resource. Reconcile differences Make requests to deployed artifacts. Make requests to other 3rd party systems. Prerequisites Service Account to give operator access Define and Deploy a CRD to act on Current go support for Operators. Why are we looking to do this in Scala.
  6. Skuber just allows you to watch a single resource Kind/Type within a single Source. At the moment it is not possible to used Skuber to filter by label selectors. This is useful if the operator is working a single/sub collection of the resources that are deployed. But for the moment it is still possible to use. What we have not included here is some of the boilerplate that you would normally see. Start and stop a stream Restarting a failed stream. Error Handling Configuration. Monitoring. Logging.
  7. Provides at least once processing semantics
  8. This is the basic approach used by operatorSDK from coreos While this works well in situations where all the resources are contained within K8s This approach falls down is if the operator is configuring resources external to k8s. In this case there are lost delete operations that don’t get processed.
  9. The reconciler function comes from the go clients implication.
  10. Points to get across Blind filter to stop event storms via the subset function Merge function… can’t do a direct replacement as K8s updates/adds some fields Other operators might add labels/scale resources extra Possible to use patch but at the moment skuber does not support that.