138

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? ?

tijko
  • 7,599
  • 11
  • 44
  • 64
Suresh Vishnoi
  • 17,341
  • 8
  • 47
  • 55

4 Answers4

171

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.

MEMark
  • 1,493
  • 2
  • 22
  • 32
Jose Armesto
  • 12,794
  • 8
  • 51
  • 56
  • 1
    Thanks for the answer.So Controller is for general purpose, however, Operator for the specific purpose. correct me If I am wrong. Why is not a good idea to implement Controller for the specific purpose? – Suresh Vishnoi Dec 18 '17 at 07:42
  • 3
    I don't understand what you mean with "general purpose" and "specific purpose" here. An Operator is a controller. It's just that when the controller adds new k8s objects to store configuration for a component like prometheus or memcached, they use the term Operator. A controller normally just watches and reacts to native k8s objects. – Jose Armesto Dec 18 '17 at 14:00
  • Please, accept the answer if you think it answers the question! – Jose Armesto Dec 21 '17 at 16:27
  • I sincerely apologise, I was trying to figure out write way to put my question in this scenario. I am still not convinced to have two different way to do the same set of the tasks in the k8s cluster. Soon I will update you. – Suresh Vishnoi Dec 21 '17 at 17:55
  • Updated answer with more takes on the subject coming from more people. – Jose Armesto Jan 13 '18 at 12:02
  • Thanks. I appreciate it – Suresh Vishnoi Jan 13 '18 at 14:03
  • So, that means, for example, if we want to update a deployment to a newer image, we change the yaml file and do a `kubectl apply -f test.yaml`. So, this is done automatically for the user with Operators using the Kubernetes APIs right? – JavaTechnical May 24 '19 at 14:40
  • From what I read in the blog posts and discussions here I understood the following: - Operator is a design pattern for infrastructure products developed on top of Kubernetes - Controller is a kind of functional object to manage other objects in Kubernetes Design pattern "Operator" is mostly based on top of controllers. Is it correct or I'm missing something? – timurb Oct 04 '21 at 09:32
30

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.

slm
  • 15,396
  • 12
  • 109
  • 124
pr-pal
  • 3,248
  • 26
  • 18
  • Very neat and elegant answer. However, please if you can add a little bit more in your second para. Probably, an example. – KnockingHeads Jun 14 '21 at 18:58
9

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.

omni
  • 4,104
  • 8
  • 48
  • 67
0

Controllers are innate objects to kubernetes that follows the control loop theory and ensures desired state matches the actual. ReplicatSet, daemonset, replication they all are pre-configured/pre-installed controllers

Operators also have controllers. Operators are a means to customize or extend the functionality of kubernetes by means of CRD (Custom Resource Definition). For eg, if you have a need to auto-inject specialized monitoring or initilization container, when a new app pod is created, then you will need write some customization (operators) as this functionality is not available in kubernetes.

Operators can be written in any language with ability to communicate with Kubernetes API server; I have mostly seen them written in Golang.

Ajit Surendran
  • 709
  • 7
  • 4