Lab 1: Kubernetes Operators
In this Lab you will learn about Kubernetes Operator basics and create your first Ansible based Operator.
The Operator Framework is an open source toolkit to manage Kubernetes native applications, called Operators, in an effective, automated, and scalable way.
-
Operators are a design pattern made public in a 2016 CoreOS blog post.
-
The goal of an Operator is to put operational knowledge into software. Previously this knowledge only resided in the minds of administrators, various combinations of shell scripts or automation software like Ansible. It was outside of your Kubernetes cluster and hard to integrate.
-
Operators implement and automate common Day-1 (installation, configuration, etc) and Day-2 (re-configuration, update, backup, failover, restore, etc.) activities in a piece of software running inside your Kubernetes cluster, by integrating natively with Kubernetes concepts and APIs.
Operators extend Kubernetes by allowing you to define a Custom Controller to watch your application and perform custom tasks based on its state (a perfect fit to automate maintenance of the stateful application we described above).
The application you want to watch is defined in Kubernetes as a new object: a Custom Resource (CR) that has its own yaml spec and object type (in K8s, a kind) that is understood by the API server.
That way, you can define any specific criteria in the custom spec to watch out for, and reconcile the instance when it doesn’t match the spec. The way an operator’s controller reconciles against a spec is very similar to native Kubernetes’ controllers, though it is using mostly custom components.
Elements of an Operator implementation
- A Custom Resource Definition (CRD) spec that defines the format of the Custom Resource
- A Custom Controller to watch our application
-
Custom code within the new controller that dictates how to reconcile our CR against the spec
-
- An Operator to manage the Custom Controller
- A Custom Resource (CR) spec that defines the application we want to watch
- A deployment for the Operator and Custom Resource