Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a Kubernetes Controller and a Kubernetes Operator?

Tags:

kubernetes

As I understand the purpose of the Kubernetes Controller is to make sure that current state is equal to the desired state. Nevertheless, Kubernetes Operator does the same job.

The list of controller in the Control-plane:

  • Deployment
  • ReplicaSet
  • StatefulSet
  • DaemonSet
  • etc

From the Google Search, I found out that there are K8s Operators such as

  • etcd Operator
  • Prometheus Operator
  • kong Operators

However, I was not able to understand why it cannot be done using Controller?

Is Operator complementing the Controllers?

What's the difference between these two design as a purpose and functionality.

What certain things need to keep in mind to choose between Controller and Operator? ?

like image 714
Suresh Vishnoi Avatar asked Dec 16 '17 17:12

Suresh Vishnoi


People also ask

Is Kubernetes operator a controller?

A Kubernetes operator is an application-specific controller that extends the functionality of the Kubernetes API to create, configure, and manage instances of complex applications on behalf of a Kubernetes user.

What is a Kubernetes controller?

In Kubernetes, controllers are control loops that watch the state of your cluster, then make or request changes where needed. Each controller tries to move the current cluster state closer to the desired state.

Is Kubernetes operator a pod?

The KubernetesPodOperator uses the Kubernetes API to launch a pod in a Kubernetes cluster. By supplying an image URL and a command with optional arguments, the operator uses the Kube Python Client to generate a Kubernetes API request that dynamically launches those individual pods.

What is Kubernetes operator vs helm?

Helm is geared towards performing day-1 operations of templatization and deployment of Kubernetes YAMLs — in this case Operator deployment. Operator is geared towards handling day-2 operations of managing application workloads on Kubernetes. You will need both when running stateful / complex workloads on Kubernetes.

What is a Kubernetes operator?

So basically, a kubernetes operator is the name of a pattern that consists of a kubernetes controller that adds new objects to the Kubernetes API, in order to configure and manage an application, such as Prometheus or etcd. In one sentence: An operator is a domain specific controller.

Why do we need a controller in Kubernetes?

The application is created by running a single Pod in the Kubernetes cluster. If the application crashes then the Pod will die. If the Pod dies then the user losses access to the application. This will create a big problem among the users. Users do not use the application which fails frequently. So we need a controller to watch the Pod status.

How does a thermostat work in Kubernetes?

The thermostat acts to bring the current state closer to the desired state, by turning equipment on or off. In Kubernetes, controllers are control loops that watch the state of your cluster, then make or request changes where needed. Each controller tries to move the current cluster state closer to the desired state.

How do you automate Kubernetes?

You can use Kubernetes to automate deploying and running workloads, and you can automate how Kubernetes does that. Kubernetes' operator pattern concept lets you extend the cluster's behaviour without modifying the code of Kubernetes itself by linking controllers to one or more custom resources.


3 Answers

I believe the term "kubernetes operator" was introduced by the CoreOS people here

An Operator is an application-specific controller that extends the Kubernetes API to create, configure and manage instances of complex stateful applications on behalf of a Kubernetes user. It builds upon the basic Kubernetes resource and controller concepts, but also includes domain or application-specific knowledge to automate common tasks better managed by computers.

So basically, a kubernetes operator is the name of a pattern that consists of a kubernetes controller that adds new objects to the Kubernetes API, in order to configure and manage an application, such as Prometheus or etcd.

In one sentence: An operator is a domain specific controller.

Update

There is a new discussion on Github about this very same topic, linking to the same blog post. Relevant bits of the discussion are:

All Operators use the controller pattern, but not all controllers are Operators. It's only an Operator if it's got: controller pattern + API extension + single-app focus.

Operator is a customized controller implemented with CRD. It follows the same pattern as built-in controllers (i.e. watch, diff, action).

Update 2

I found a new blog post that tries to explain the difference as well.

like image 65
Jose Armesto Avatar answered Oct 23 '22 07:10

Jose Armesto


In Kubernetes, most of the operations happen in an asynchronous manner.

For instance, when one creates a ReplicaSet object (picking a simpler object), this is the sequence that happens:

  1. We send the request to the Kube api-server.
  2. The kube-api server has a complex validation
    • Ensures that the user has the RBAC credential to create the RS in the given namespace
    • The request is validated by all the configured admission controllers
  3. Finally the object is just written to ETCD - nothing more nothing less

Now, it is the responsibility of the various Kubernetes controllers to watch the ETCD changes and actually execute the necessary operations. In this case, the ReplicaSet controller would be watching for the changes in ETCD (e.g. CRUD of ReplicataSets) and would create the Pods as per the replica count etc.

Now, coming to Operators, conceptually they are very similar to Kubernetes controllers. But they are used with third-party entities. In Kubernetes, there is a concept of CRDs, where vendors can define their own CRD which is nothing but a custom (e.g. Vendor specific) kubernetes object type. Very similar to the manner in which Kubernetes controllers read to the CRUD of Kubernetes objects, these operators respond to the operations on the corresponding CRDs. E.g. Kong operator can create new API entries in the Kong API server when a new API CRD object is created in the Kubernetes cluster.

like image 20
pr-pal Avatar answered Oct 23 '22 08:10

pr-pal


TL;DR:

  • Controller == Works on vanilla K8s resources
  • Operator == a Controller that adds custom resources (CRDs) required for it's operation

Change my mind but in my opinion the difference is negligible and the terms rather confuse people then actually adding value to a discussion. I therefore would use them interchangeablely.

like image 35
omni Avatar answered Oct 23 '22 07:10

omni