Dernière mise à jour : 15 sept. 2021
As you already know, Kubernetes is a great and popular container orchestrator. You can use its features to deploy your applications and it will take care of many things like scaling, rollouts and rollbacks or even self-healing as described below.
To do so, you will write manifests in YAML format (deployments, services, configmaps etc.) for each of your application to let Kubernetes know what to create.
These applications can be stateful or stateless.
Quick reminder, a stateless process or application does not save client data generated in one session for use in the next session with that client. There is no stored knowledge or reference to past transactions.
However, stateful applications can be returned to again and again. They’re performed with the context of previous transactions and the current transaction may be affected by what happened during previously.
Stateful application : a shop where each time you select an item and add it in your cart. It has to remind the state of your cart.
Stateless application : an app used just for looking for an information in a database (i.e a weather forecast service.) Previous state is not relevant here because data is stored somewhere else.
To manage Stateful applications in Kubernetes, you will obviously need more "people" during their entire lifecycle.
For example, if you have several MySQL replicas, they will all have their own state and you won't be able to update them in any order and all replicas must have a constant communication between them to let data consistent. Furthermore, even more manual operations will occur while scaling up or scaling down like network configuration for new replicas or removed replicas' data management.
It means that you will need, for such configuration, people and skills to operate these applications !
And here is why you need Operators !
You can see Operators as "Engineers" who would provide with software the skills of "Engineers", who would encode in software, the skills of an expert administrator to perform things such as : how to deploy the app, how to recover it or how to create a cluster of my app ?
Just like Helm charts, Kubernetes Operators also package applications into easy-to-deploy bundles, but they do much more than that ! (we will see how they can be complementary later)
Indeed, you can use Kubernetes Operators to do things like deploy a stateful application and its database schema in a completely automatic way, or deploy an application across a cluster that is configured in a particular way to achieve high availability !
Think Operators as a great way to make things reusable and automated for stateful applications.
How Operators work ?
Operators work by extending the Kubernetes control plane and API. In its simplest form, an Operator adds an endpoint to the Kubernetes API, called a custom resource definition (CRD), along with a control plane component that monitors and maintains resources of the new type.
So the most common way to deploy an Operator is to add the Custom Resource Definition and its associated Controller to your cluster as described below :
Thus, Operators will have the same kind of loop as Kubernetes :
They will check for updates in the configuration file or noticed any changes or error and act as expected !
Helm vs Operators ?
When I discovered Operators I was kind of confused with Helm which both looked like a way of templating apps for me.
You don't have to see Helm and Operators as competitors but as complementary or to be used in different types of use cases !
With Helm you can package your applications. Just like an RPM package on Linux ! So you can continue to use Helm when deploying a simple application and when few customizations are required.
However, you will still need Operators to perform actions described previously such as deploy stateful applications. It will then manage a set of instances, reconciling its state according according to the mentioned specs of its CR.
Helm can´t do that.
However, you can make them complementary while implementing your own Operators manually or through different frameworks !