Slide 1

Slide 1 text

Custom Resources for Cloud Native DevOps

Slide 2

Slide 2 text

FIND ME github.com/jelmersnoeck twitter.com/jelmersnoeck Jelmer Snoeck ABOUT ME - OX Tech Lead at manifold.co - Kubernetes - Terraform - Kubelist Editor

Slide 3

Slide 3 text

$ tree custom-resources-cloud-native-devops/ - What are Custom Resources - How to build Custom Resources - Publishing Custom Resources

Slide 4

Slide 4 text

Custom Resource (Definitions) Photo by The Roaming Platypus on Unsplash

Slide 5

Slide 5 text

A custom resource is an extension of the Kubernetes API that is not necessarily available on every Kubernetes cluster. In other words, it represents a customization of a particular Kubernetes installation.

Slide 6

Slide 6 text

Custom Resource Definition (CRD)

Slide 7

Slide 7 text

The CustomResourceDefinition API resource allows you to define custom resources. Defining a CRD object creates a new custom resource with a name and schema that you specify. The Kubernetes API serves and handles the storage of your custom resource.

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Validation

Slide 12

Slide 12 text

Open API Schema

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Admission Webhooks

Slide 17

Slide 17 text

Printer Columns

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Finalizers

Slide 21

Slide 21 text

Controller vs Operator

Slide 22

Slide 22 text

Controller <> Operator - Controller purely interacts with k8s objects (even custom ones) - Operator knows about a different domain outside of k8s (etcd, prometheus, …)

Slide 23

Slide 23 text

Some CRDs in the wild

Slide 24

Slide 24 text

- cert-manager - prometheus-operator - ingress-nginx-controller - contour - ingress-monitor - istio Examples

Slide 25

Slide 25 text

What’s under the hood Photo by Wade Lambert on Unsplash

Slide 26

Slide 26 text

Defining APIs

Slide 27

Slide 27 text

API Definitions

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Generated runtime.Object code

Slide 30

Slide 30 text

type Object interface { GetObjectKind() schema.ObjectKind DeepCopyObject() Object }

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Scheme Definitions

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Generating Clients

Slide 36

Slide 36 text

k8s.io/code-generator/generate-groups.sh

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

./vendor/k8s.io/code-generator/generate-groups.sh \ all \ github.com/jelmersnoeck/ingress-monitor/pkg/client/generated \ github.com/jelmersnoeck/ingress-monitor/apis \ ingressmonitor:v1alpha1 \ --go-header-file boilerplate.go.txt

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Controller

Slide 43

Slide 43 text

Cache Informers

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

Event Handlers

Slide 47

Slide 47 text

type ResourceEventHandler interface { OnAdd(obj interface{}) OnUpdate(oldObj, newObj interface{}) OnDelete(obj interface{}) }

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Workqueue

Slide 51

Slide 51 text

Built in queue features ● Fair: items processed in the order in which they are added. ● Stingy: a single item will not be processed multiple times concurrently, and if an item is added multiple times before it can be processed, it will only be processed once. ● Multiple consumers and producers. In particular, it is allowed for an item to be reenqueued while it is being processed. ● Shutdown notifications.

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

Label Selectors

Slide 56

Slide 56 text

Labels

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

Survive Rescheduling

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

Testing

Slide 66

Slide 66 text

Testing - Fake Clients - Add wrappers to test informers - Use of testing.Fake Actions

Slide 67

Slide 67 text

Publishing Photo by chuttersnap on Unsplash

Slide 68

Slide 68 text

RBAC

Slide 69

Slide 69 text

Survive Rescheduling

Slide 70

Slide 70 text

Validation

Slide 71

Slide 71 text

Resource Utilization

Slide 72

Slide 72 text

Application Structuring

Slide 73

Slide 73 text

Observability

Slide 74

Slide 74 text

Thanks! Questions? @jelmersnoeck manifold.co