Operator
最后更新于
最后更新于
The Operator, brought to you by CoreOS, is a framework designed to simplify and streamline the management of complex, stateful applications. It is a controller that perceives the status of applications, extending Kubernetes API for automated creation, management, and configuration of application instances.
You can identify some recommended Operator examples within the Kubernetes community on OperatorHub.io.
The Operator works by extending new application resources through CustomResourceDefinition (CRD) and ensuring the application is in the desired state by using a controller. For instance, the etcd operator emulates the behavior of etcd cluster management through the following three steps:
Observing the current state of the cluster via the Kubernetes API;
Analyzing the differences between the current state and the desired state;
Modifying these discrepancies by calling the etcd cluster management API or the Kubernetes API.
Since an Operator is a controller that's attentive to application states, the key to implementing an Operator is to encapsulate all the operations managing the application state into the configuration resources and the controller. Generally speaking, Operator needs to comprise the following features:
Deploy the Operator itself as a Deployment
Automate the creation of a CustomResourceDefinition (CRD) resource type, and the user can use this type to create application instances
Use built-in Service/Deployment in Kubernetes to manage applications
Be backward-compatible and its carry-over or deletion should not affect the state of the application
Support application version update
Test Pod failure, configuration error, network error, and other abnormal situations
The simplest way to create a new Operator is to utilize the Operator Framework. For instance, creating the most basic Operator only requires these steps:
(1) Install the operator-sdk tool:
(2) Initialize the project:
(3) Add CRD definition and controller:
(4) Implement Controller, Reconciler, and other control logics.
(5) Deploy Operator to the Kubernetes cluster and create resources through customized CRD.
You can refer to this example for a complete guide.
For ease of description, we will use Etcd Operator as an example - Etcd Operator.
Deploy the Operator in Kubernetes: You can deploy the corresponding Operator by creating a Deploymet instance in the Kubernetes cluster. Here is an example of a Yaml:
Check if the operator is successfully deployed:
Here is an example of a yaml file for a stateful service:
Deploy the corresponding stateful service:
Rook Operator: Cloud-native storage orchestrator
StatefulSets: StatefulSets provide DNS, persistent storage, etc., for stateful services, while Operator can automatically handle complex scenarios such as service failure, backup, reconfiguration, etc.
Puppet: Puppet is a static configuration tool, while Operator can keep the application in the desired state in real time and dynamically.
Helm: Helm is a packaging tool that can deploy multiple applications together, while Operator can be considered a supplement to Helm, used to dynamically ensure the normal operation of these applications.