Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

Kyle Bai

March 28, 2019

More Decks by Kyle Bai

Other Decks in Programming


  1. @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
  2. @k2r2bai • Inspired by a true story • How to

    implement LINE bot operator? • Live Demo Agenda Today I would like to talk about
  3. @k2r2bai • Self-healing • Horizontal scaling • Service discovery and

    Load balancing • Automated rollouts and rollbacks • Secrets and configuration management • Storage orchestration Kubernetes
  4. @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
  5. @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
  6. @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)
  7. @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
  8. @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
  9. @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
  10. @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
  11. @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"` }