What is the Operator pattern?

Automate tasks is always something particular. When we want to do some tasks we need to be able to react or being triggered on some specific events. But a lot of events can’t be listen easily, especially in a Kubernetes Cluster. So today, we will see h…


This content originally appeared on DEV Community and was authored by Maxime Guilbert

Automate tasks is always something particular. When we want to do some tasks we need to be able to react or being triggered on some specific events. But a lot of events can't be listen easily, especially in a Kubernetes Cluster. So today, we will see how to try to resolve it, with the operator pattern.

TLDR

Operators are software extensions to Kubernetes that make use of custom resources to manage applications and their components. Operators follow Kubernetes principles, notably the control loop.

Source - Kubernetes Documentation

What is the operator pattern ?

This pattern allows Kubernetes users to create their own resource controller in order to automate the management of their application/product stack.

The operator pattern uses CRDs (Custom Resource Definition) in order to facilitate the resources/tasks configuration.

And since it follows a lot of Kubernetes principles as the control loop, your operator will be (depending your configuration and what you've code in your code) able to monitor resources that it has created and/or other resources on your cluster.

Here is a scheme coming from the RedHat blog illustrating the context.

Image description

Example

In order to be more concrete, here are some examples.

1. Automate to avoid to repeat multiple deployments

If you are in a team who deploy and give access to each team of your company a complete tool stack to collect and visualize their metrics, you need to deploy manually for each of them the following stack :

  • Prometheus
  • OpenTelemetry
  • Grafana
  • Postgres

Image description

In this situation, instead of repeating the same task to deploy all theses apps and all the related components (Services, configmaps, service accounts...), you can just create an operator to let it manage
this kind of tasks for you with a CRD to contain all the configurations which can be updated.

For example, the CRD can be named ObservabilityStack and each time a new instance of this resource will be created, it will automatically create all the resources you've defined.

Image description

2. Automate to avoid manual errors

People who already managed StatefulSet knows what I will talk about.

When we manage some applications (especially the apps with volumes), it can happend that we need to do some specific tasks in a specific order in order to create, update or delete something.

So if you only have 3 or 4 resources of this kind, it can be correct to do it with bash scripts or ansible scripts. But if you have 50? 100? or more?

In this kind of situation, the operator pattern can help you too. If you are able to define all the tasks you need to do, they will be executed in the required case.

Thus, this applications won't be dependant anymore of you during an update. And it will make your life easier.

3. Automate configuration

In this example, imagine you are in a team who manage a Nginx which expose all the APIs of your company. And all the APIs and your nginx are in the same Kubernetes cluster. Once a new one is deployed, you need to update your config file with the new endpoints in all the environments. Also your company loves microservices, so you have new APIs and updates every week.

Also some of them are renamed, moved or even deleted. But you are not always in the loop, so if one api doesn't work anymore, you receive calls to understand what's happening.

As you already understand, operators are a solution to help you in this case. As you are able to track resources on all the cluster, you can see if some deployements are added, renamed or deleted! So with this, you are able to trigger when these kind of event happend and you can update your configuration file!

Conclustion

With all this examples, I think you understand the principle and the utility of this pattern.

Now, if we want to go further, we need put our hands in the code. So we will see in the following post how to create an operator!

I hope it will help you and if you have any questions (there are not dumb questions) or some points are not clear for you, don't hesitate to add your question in the comments or to contact me directly on LinkedIn.

You want to support me?

Buy Me A Coffee


This content originally appeared on DEV Community and was authored by Maxime Guilbert


Print Share Comment Cite Upload Translate Updates
APA

Maxime Guilbert | Sciencx (2023-06-05T13:14:00+00:00) What is the Operator pattern?. Retrieved from https://www.scien.cx/2023/06/05/what-is-the-operator-pattern/

MLA
" » What is the Operator pattern?." Maxime Guilbert | Sciencx - Monday June 5, 2023, https://www.scien.cx/2023/06/05/what-is-the-operator-pattern/
HARVARD
Maxime Guilbert | Sciencx Monday June 5, 2023 » What is the Operator pattern?., viewed ,<https://www.scien.cx/2023/06/05/what-is-the-operator-pattern/>
VANCOUVER
Maxime Guilbert | Sciencx - » What is the Operator pattern?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/06/05/what-is-the-operator-pattern/
CHICAGO
" » What is the Operator pattern?." Maxime Guilbert | Sciencx - Accessed . https://www.scien.cx/2023/06/05/what-is-the-operator-pattern/
IEEE
" » What is the Operator pattern?." Maxime Guilbert | Sciencx [Online]. Available: https://www.scien.cx/2023/06/05/what-is-the-operator-pattern/. [Accessed: ]
rf:citation
» What is the Operator pattern? | Maxime Guilbert | Sciencx | https://www.scien.cx/2023/06/05/what-is-the-operator-pattern/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.