Slide 1

Slide 1 text

@k2r2bai Chatbot as a Service on Container 1 ⽩白凱仁(Kyle Bai)

Slide 2

Slide 2 text

@k2r2bai About Me ⽩白凱仁(Kyle Bai) • Between Jobs. : ( • Contributor to multiple OSS. • Certified Kubernetes Administrator/Developer. • Co-organizer of Cloud Native Taiwan User Group. • Interested in emerging technologies. @kairen https://k2r2bai.com

Slide 3

Slide 3 text

@k2r2bai Cloud Native Taiwan User Group SDN, Cloud Native, System • Hosted a meetup and conference for sharing and discussing everything related to cloud native and Kubernetes ecosystem. • Hosted a workshop to get local user on-boarded to Kubernetes experience. • Boosted a local community to contribute Kubernetes and

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

@k2r2bai Inspired by a true story

Slide 6

Slide 6 text

@k2r2bai One Today….

Slide 7

Slide 7 text

@k2r2bai ME FRIEND How to become a PROFESSIONAL HUNTER?

Slide 8

Slide 8 text

@k2r2bai ME FRIEND You need an AIBO!!

Slide 9

Slide 9 text

@k2r2bai

Slide 10

Slide 10 text

@k2r2bai ME FRIEND

Slide 11

Slide 11 text

@k2r2bai How to become a PROFESSIONAL AGENT? ME FRIEND

Slide 12

Slide 12 text

@k2r2bai You need a TERMINAL!! ME FRIEND

Slide 13

Slide 13 text

@k2r2bai So I think we need…

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

Slide 19

Slide 19 text

@k2r2bai But…

Slide 20

Slide 20 text

@k2r2bai How to deploy/manage/configure bots?

Slide 21

Slide 21 text

@k2r2bai How to add messages and events easily?

Slide 22

Slide 22 text

@k2r2bai • Process-level isolation, possibly less secure. • High coupling for the kernel. • Native performance. • Startup time in milliseconds. • Lightweight Containers(OS-Level Virtualization) Application Virtualization libs app kernel libs app libs app libs app

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

@k2r2bai I have a Chatbot

Slide 25

Slide 25 text

@k2r2bai I have a Kubernetes

Slide 26

Slide 26 text

@k2r2bai Ugh…

Slide 27

Slide 27 text

@k2r2bai Chatbot Operator

Slide 28

Slide 28 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 29

Slide 29 text

@k2r2bai Bot, Event and EventBinding

Slide 30

Slide 30 text

@k2r2bai How to implement?

Slide 31

Slide 31 text

@k2r2bai Operator https://coreos.com/blog/introducing-operators.html “An Operator is an application-specific controller that extends the Kubernetes API to create, configure, and manage instances of complex stateful applications on behalf of a Kubernetes user. It builds upon the basic Kubernetes resource and controller concepts but includes domain or application-specific knowledge to automate common tasks.” —- Brandon Philips, CoreOS

Slide 32

Slide 32 text

@k2r2bai • 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. • Hides raw complexities of controllers. • Used to build native Kubernetes applications. Parts of the Operator

Slide 33

Slide 33 text

@k2r2bai Why are Kubernetes Operators so important?

Slide 34

Slide 34 text

@k2r2bai

Slide 35

Slide 35 text

@k2r2bai

Slide 36

Slide 36 text

@k2r2bai Problems: learn to write operators

Slide 37

Slide 37 text

@k2r2bai A service that listens for events and acts to converge the system to the desired state from the actual state. Custom Controllers • Automate administration tasks as if they were a native Kubernetes component. • State-of-the-art for building distributed apps in Kubernetes. • Interact with the Kubernetes API server.

Slide 38

Slide 38 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 39

Slide 39 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 40

Slide 40 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 41

Slide 41 text

@k2r2bai

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

@k2r2bai // +genclient // +k8s:deepcopy-gen:inteDaces=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 44

Slide 44 text

@k2r2bai Live Demo

Slide 45

Slide 45 text

@k2r2bai Summary

Slide 46

Slide 46 text

@k2r2bai 還不趕快來來學 Kubernetes https://kubernetes.io/docs/tutorials/kubernetes-basics/

Slide 47

Slide 47 text

@k2r2bai • https://learning.oreilly.com/library/view/programming-kubernetes/9781492047094/ • https://github.com/kubeflow/tf-operator/issues/300 • https://stackoverflow.com/questions/47848258/kubernetes-controller-vs-kubernetes- operator?rq=1 • https://github.com/operator-framework/awesome-operators • https://github.com/kubernetes-sigs/kubebuilder • https://github.com/operator-framework References

Slide 48

Slide 48 text

@k2r2bai Q &A

Slide 49

Slide 49 text

@k2r2bai KAIREN OUT!! THANK YOU!!!