k8s operator

what is it

An Operator is software that encodes this domain knowledge and extends the Kubernetes API through the third party resources mechanism, enabling users to create, configure, and manage applications. Like Kubernetes’s built-in resources, an Operator doesn’t manage just a single instance of the application, but multiple instances across the cluster.

Operator 的設計旨在簡化複雜有狀態應用管理,其通過CRD擴展 Kubernetes API 來自動創建、管理和配置應用實例。其本質上是針對特定的場景去做有狀態服務,或者說針對複雜應用場景,去簡化其運維管理的工具。

Operator以deployment的形式部署到K8S中。部署完這個Operator之後,想要部署一個集羣,其實很方便。因爲不需要再去管理這個集羣的配置信息了,只需要創建一個CRD,指定創建多少個節點,需要什麼版本,Operator會監聽該資源對象,創建出符合配置要求的集羣,從而大大簡化運維的難度和成本。

Operator 實際上作爲kubernetes自定義擴展資源註冊到controller-manager,通過list and watch的方式監聽對應資源的變化,然後在週期內的各個環節做相應的協調處理。

Custom resources can appear and disappear in a running cluster through dynamic registration, and cluster admins can update custom resources independently of the cluster itself. Once a custom resource is installed, users can create and access its objects using kubectl, just as they do for built-in resources like Pods.

How is it built

Operators build upon two central Kubernetes concepts: Resources and Controllers.
As an example, the built-in ReplicaSet resource lets users set a desired number number of Pods to run, and controllers inside Kubernetes ensure the desired state set in the ReplicaSet resource remains true by creating or removing running Pods.

An Operator builds upon the basic Kubernetes resource and controller concepts and adds a set of knowledge or configuration that allows the Operator to execute common application tasks.

For example, when scaling an etcd cluster manually, a user has to perform a number of steps:

  1. create a DNS name for the new etcd member,
  2. launch the new etcd instance,
  3. and then use the etcd administrative tools (etcdctl member add) to tell the existing cluster about this new member.

Instead with the etcd Operator a user can simply increase the etcd cluster size field by 1.

Example 2: A backup is triggered by a user with kubectl

ref:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章