Slide 1

Slide 1 text

@k2r2bai An operator deploys/manages/ configures LINE bot atop Kubernetes SDN x Cloud Native Meetup #14

Slide 2

Slide 2 text

@k2r2bai About Me ⽩白凱仁(Kyle Bai) • RDSS at inwinSTACK. • Interested in emerging technologies. • Kubernetes Projects Contributor. • Certified Kubernetes Administrator. • CNTUG(Cloud Native Taiwan User Group) co-organizer. • Kubernetes 200+ nodes experience. @kairen([email protected]) https://k2r2bai.com

Slide 3

Slide 3 text

@k2r2bai • Inspired by a true story • How to implement LINE bot operator? • Live Demo Agenda Today I would like to talk about

Slide 4

Slide 4 text

Inspired by a true story

Slide 5

Slide 5 text

@k2r2bai One Today….

Slide 6

Slide 6 text

@k2r2bai ME FRIEND How to become a PROFESSIONAL HUNTER?

Slide 7

Slide 7 text

@k2r2bai ME FRIEND You need an AIBO!!

Slide 8

Slide 8 text

@k2r2bai

Slide 9

Slide 9 text

@k2r2bai ME FRIEND

Slide 10

Slide 10 text

@k2r2bai How to become a PROFESSIONAL AGENT? ME FRIEND

Slide 11

Slide 11 text

@k2r2bai You need a TERMINAL!! ME FRIEND

Slide 12

Slide 12 text

@k2r2bai So I think we need…

Slide 13

Slide 13 text

@k2r2bai

Slide 14

Slide 14 text

@k2r2bai

Slide 15

Slide 15 text

@k2r2bai

Slide 16

Slide 16 text

@k2r2bai

Slide 17

Slide 17 text

@k2r2bai

Slide 18

Slide 18 text

@k2r2bai But…

Slide 19

Slide 19 text

@k2r2bai How to deploy/manage/configure?

Slide 20

Slide 20 text

@k2r2bai • Self-healing • Horizontal scaling • Service discovery and Load balancing • Automated rollouts and rollbacks • Secrets and configuration management • Storage orchestration Kubernetes

Slide 21

Slide 21 text

@k2r2bai I have a chatbot

Slide 22

Slide 22 text

@k2r2bai I have a Kubernetes

Slide 23

Slide 23 text

@k2r2bai Ugh… Bot Operator

Slide 24

Slide 24 text

@k2r2bai LINE Bot Operator

Slide 25

Slide 25 text

@k2r2bai • Bot: defines the desired state of the Bot deployment. • Event: defines eventing rules for a bot instance. • EventBinding: defines the set of events to be used by the bot. You select Events to be bound using labels and label selectors. Bot, Event and EventBinding

Slide 26

Slide 26 text

@k2r2bai Bot, Event and EventBinding

Slide 27

Slide 27 text

@k2r2bai 我知道這很ㄎ⼀一ㄤ..

Slide 28

Slide 28 text

@k2r2bai 所以直接來來講怎麼實作吧...

Slide 29

Slide 29 text

How to implement LINE bot operator?

Slide 30

Slide 30 text

@k2r2bai • CRD - Custom Resource Definition: definition of new resource in kube that can be used in yaml to specify instances (eg Statefulsets, pre-official cron jobs, prometheus). • Controller: A service that listens for events and acts to converge the system to the desired state from the actual state. • Operator: A controller built with the listen-act pattern based on events from kubernetes on resources. Usually encapsulates a human as an expert system to operate a service. Definitions

Slide 31

Slide 31 text

@k2r2bai • 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. • Do not require programming CRD(CustomResourceDefinition)

Slide 32

Slide 32 text

@k2r2bai • Kubernetes 1.7 has added an important feature called Custom Controllers. • It enables developers to extend and add new functionalities, replace existent ones (like replacing kube-proxy for instance). • And of course, automate administration tasks as if they were a native Kubernetes component. Custom Controllers

Slide 33

Slide 33 text

@k2r2bai • CRD to specify new resource that the operator manages (optional). • Controller for listening and dispatching events (uses informers, watchers and event handlers) -> runs as a k8s pod/deployment. • API classes to specify a model that represents the data in the CRD. • Internal Model Objects to manipulate the k8s client to create, update and delete resources based on state. • Events: • Added • Updated • Deleted Parts of the Operator

Slide 34

Slide 34 text

@k2r2bai • Allows manipulation of resource state (eg creation of pod, modification of configmap, deletion of persistent volume). • List resources. • Get details about current resource state. • Creates custom controller. client-go https://github.com/kubernetes/client-go

Slide 35

Slide 35 text

@k2r2bai

Slide 36

Slide 36 text

@k2r2bai • Go does not have generics in the language. • Code generation can be done using k8s code generation scripts. • Generation of typed: • Informers • Listers • Clientsets • This should be part of your build process. Code Generation https://github.com/kubernetes/code-generator

Slide 37

Slide 37 text

@k2r2bai // +genclient // +k8s:deepcopy-gen:inte4aces=k8s.io/apimachinery/pkg/runtime.Object type Bot struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata"` Spec BotSpec `json:"spec"` Status BotStatus `json:"status,omitempty"` }

Slide 38

Slide 38 text

Live Demo

Slide 39

Slide 39 text

@k2r2bai KAIREN OUT!! THANK YOU!!!