An operator deploys/manages/configures LINE bot atop Kubernetes

An operator deploys/manages/configures LINE bot atop Kubernetes

Designed and developed an operator to manage/deploy/configure LINE bot atop Kubernetes.

5a84ea9a0afaca03be45b87dde58e51c?s=128

Kyle Bai

March 28, 2019
Tweet

Transcript

  1. @k2r2bai An operator deploys/manages/ configures LINE bot atop Kubernetes SDN

    x Cloud Native Meetup #14
  2. @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(k2r2.bai@gmail.com) https://k2r2bai.com
  3. @k2r2bai • Inspired by a true story • How to

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

  5. @k2r2bai One Today….

  6. @k2r2bai ME FRIEND How to become a PROFESSIONAL HUNTER?

  7. @k2r2bai ME FRIEND You need an AIBO!!

  8. @k2r2bai

  9. @k2r2bai ME FRIEND

  10. @k2r2bai How to become a PROFESSIONAL AGENT? ME FRIEND

  11. @k2r2bai You need a TERMINAL!! ME FRIEND

  12. @k2r2bai So I think we need…

  13. @k2r2bai

  14. @k2r2bai

  15. @k2r2bai

  16. @k2r2bai

  17. @k2r2bai

  18. @k2r2bai But…

  19. @k2r2bai How to deploy/manage/configure?

  20. @k2r2bai • Self-healing • Horizontal scaling • Service discovery and

    Load balancing • Automated rollouts and rollbacks • Secrets and configuration management • Storage orchestration Kubernetes
  21. @k2r2bai I have a chatbot

  22. @k2r2bai I have a Kubernetes

  23. @k2r2bai Ugh… Bot Operator

  24. @k2r2bai LINE Bot Operator

  25. @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
  26. @k2r2bai Bot, Event and EventBinding

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

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

  29. How to implement LINE bot operator?

  30. @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
  31. @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)
  32. @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
  33. @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
  34. @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
  35. @k2r2bai

  36. @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
  37. @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"` }
  38. Live Demo

  39. @k2r2bai KAIREN OUT!! THANK YOU!!!