Ericsson Internal |2018-02-21
Operators - The Future
of Kubernetes
Hands-On Workshops On Operators and
Tekton
Krishna
Venkata Laxmikanth Vajinapally
Shabri
nath
Mota
mary
2.
Ericsson Internal |2018-02-21
● Stateless Vs StateFul
● What is an Operator?
● Operator Framework
● Operators Types
● Best Practices
● Hands-on Go Based Operator
● What is Tekton ?
● Tekton CRDs
● Hands-On Tekton Pipeline
Agenda
3.
Ericsson Internal |2018-02-21
Stateless Vs Stateful Applications
— Stateless
1. Kubernetes provides powerful in built features to deploy stateless applications e.g.
Web Apps
2. Can be destroyed, relocated and upgrade easily.
3. Service Exposes deployments.
— Stateful
1. Requires domain Knowledge to Deploy, Manage and Scale e.g. Databases.
2. Application specific notions of clustering and interconnectivity.
3. Coordination for authorization and authentication of members.
4. Coordination while scaling in and out.
5. Complex application specific Backup, Healing and life cycle management
4.
Ericsson Internal |2018-02-21
— This is where Operators Come in, all the cons of Stateful can be achieved by
Operators.
— Operators fill the gap of the application specific things that Kubernetes can’t do.
— Operators extend Kubernetes functionality.
— Human experience as code.
— Focus on desired state.
— Complex, Manual Operational tasks become a single line of Config.
Kubernetes Doesn’t and Operators
Does
5.
Ericsson Internal |2018-02-21
“An Operator is a method of packaging, deploying and managing a
Kubernetes application. A Kubernetes application is an application
that is both deployed on Kubernetes and managed using the
Kubernetes APIs and kubectl tooling.”
What is Operator?
6.
Ericsson Internal |2018-02-21
Custom
Resources
Definition
Custom
Controller
Applicatio
n
knowledg
e
Operato
r
Ericsson Internal |2018-02-21
— Operators take advantage of Custom Resource Definition(CRD).
— CRD’s are extensions of the Kubernetes API to register new Resource.
— Creating a Custom Resource(CR) from CRD’s.
— Operator monitors for new CR request, acknowledges and creates the CR.
— It Can be used like any other native Kubernetes Resource.
Operator Interaction With
Kubernetes
9.
Ericsson Internal |2018-02-21
— Business logic is required.
— Application uses a declarative API.
— Automation that watches for updates of Kubernetes object.
— Create or update resources using Kubernetes API.
When to Choose Creating A
Operator?
10.
Ericsson Internal |2018-02-21
Etcd Operator
Observ
e
Analyze
Act
— Cluster A has 3 Running Pods
Name: summit-etcd-0 Version 2.9.1
Name: summit-etcd-1 Version 2.9.2
Name: summit-etcd-1 Version 2.9.1
— Desired = False
Difference in Configuration
Version should be 2.9.2
— Cluster
Clean, Backup Cluster
Upgrade to 2.9.2
11.
Ericsson Internal |2018-02-21
— Operator SDK
Supports developers in bootstrapping and building an Operator based on their expertise
without requiring knowledge of Kubernetes API complexities
— Operator Lifecycle Manager
Helps you to install, update, and generally manage the lifecycle of all of the operators (and
their associated services) running across your clusters
— Operator Metering
Metering records historical cluster usage, and can generate usage reports showing usage
breakdowns by pod or namespace over arbitrary time periods
Operator Framework
12.
Ericsson Internal |2018-02-21
Operator Type What the SDK generates What you need to define
Go Operator • General go program structure
• Boilerplate code to talk to the
Kubernetes API
• Boilerplate code to watch for
Kubernetes objects of interest
• An entry point to the reconciliation
loop
• Custom objects via CRDs
• Control loop logic in Go
Ansible Operator • A Go program that runs an Ansible
playbook or role every time a certain
type of object is detected / modified
• Custom objects via CRD
Helm Operator • A Go program that reads a helm chart
and deploys all its resources
• Watch statements to detect changes in
the custom objects specification, re-
deploying all resources with updated
values
• The location / repository of the helm
chart
Operator Types Using Operator SDK
Ericsson Internal |2018-02-21
Project Layout For Go Based Operator
SDK
File/Folders Purpose
cmd Contains manager/main.go which is the main program of the operator. This instantiates a new
manager which registers all custom resource definitions under pkg/apis/... and starts all
controllers under pkg/controllers/... .
pkg/apis Contains the directory tree that defines the APIs of the Custom Resource Definitions(CRD). Users
are expected to edit the pkg/apis/<group>/<version>/<kind>_types.go files to define the API for
each resource type and import these packages in their controllers to watch for these resource
types.
pkg/controller This pkg contains the controller implementations. Users are expected to edit
the pkg/controller/<kind>/<kind>_controller.go to define the controller's reconcile logic for
handling a resource type of the specified kind.
build
Contains the Dockerfile and build scripts used to build the operator.
deploy Contains various YAML manifests for registering CRDs, setting up RBAC, and deploying the
operator as a Deployment.
go.mod go.sum The Go mod manifests that describe the external dependencies of this operator.
vendor The golang vendor directory that contains local copies of external dependencies that satisfy Go
imports in this project. Go modules manages the vendor directory directly. This directory will not
Ericsson Internal |2018-02-21
Awesome Operators ..!!
— Rook
1. Rook-Ceph
2. Rook-EdgeFS
— Kube-Virt
— Tomcat and Many More
21.
Ericsson Internal |2018-02-21
Operators Hands-on Demo
In this demo, we will build a GO-based Operator called Cloner. The project name is openinfra-
summit. kind is kind: Cloner
— Create a project using the operator-sdk command line.
— Add a new CRD API.
— Update cloner_types.go as required with custom Specs and Status to deploy our
application Cloner.
— Run generate k8s and openapi to update the generated code for that resource type.
— Add a new Controller.
— Register our new CRD with Kubernetes APIServer.
— Setup RBAC and Deploy our new application called Cloner.
Ericsson Internal |2018-02-21
What is Tekton:
— Tekton itself is an Operator.
— Tekton is an open source framework to configure and run CI/CD pipelines within a
Kubernetes cluster.
— Tekton is deployed on Kubernetes.
— Installation:
kubectl apply --filename
https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.7.0/release.yaml
Operator: Tekton
24.
Ericsson Internal |2018-02-21
Operator= CRDs + Domain specific knowledge + Controller
CRDs : Custom Resource Definitions
— Extending Kubernetes APIs
— Once installed, Users can create and access its objects using kubectl
Controller : Controllers act on Resources to maintains desired state.
Tekton: CRDs
Ericsson Internal |2018-02-21
Task:
— Contains multiple steps
— Steps are executed sequentially
— Every Task is a Pod
— Takes input and output parameters
Step:
— Smallest Building block of a Task
— Not a CRD
— Each step is a container
— Runs commands within the container
Task
27.
Ericsson Internal |2018-02-21
— Tasks can be executed in any order using Pipeline
— Links output and input of Tasks
— Triggered using PipelineRuns
Pipeline
Task
Task
Task Task
Task
28.
Ericsson Internal |2018-02-21
— Predefined input/output
— Used as input and output of Tasks
— Most common resource types are Git and Image
PipelineResource
29.
Ericsson Internal |2018-02-21
— PipelineRun and TaskRun are created to trigger Pipeline and Task respectively.
— PipelineRun creation triggers creation of TaskRuns
— PipelineRun uses PVC to share resources between Tasks
PipelineRun and TaskRun
30.
Ericsson Internal |2018-02-21
— Task, Pipeline are declared once and re-used.
— TaskRun, PipelineRun are used to invoke respective Tasks and Pipelines.
— PipelineResource provides runtime info like Git repo, Image registry to Runs.
Tekton CRDs Overview
Pipeline
Resource
PipelineRun
Task
Ericsson Internal |2018-02-21
Tekton Hands-On Demo
— This pipeline demonstrates creating an container image from Dockerfile and
pushing the newly created image to Dockerhub.
— Overview of Steps Involved
1. Creating pipeline resources for Git repo and DockerHub
2. Creating Task
3. Creating TaskRun to invoke Task
— Follow steps from:
https://github.com/kvenkata986/shanghai-summit/tree/master/tekton
33.
Ericsson Internal |2018-02-21
Tekton Pipeline Flow
PipelineResourc
e
TaskRun Task
PipelineResourc
e