Kubernetes Operator & Custom Resource Definitions

R ChanR Chan
3 min read

Today, we will learn about what is a k8s operator, where are these used and a brief introduction about stateless and stateful applications, control loops, and CRDs.

StateFUL and StateLESS application

Let us first talk about StateFul and StateLESS applications. Stateless apps don't store session or transaction info. Each transaction is made from scratch. An example of this is simple applications without databases. While StateFul apps are just the opposite. They store the state of applications. Examples are databases like MySQL, Postgres, etc. Read more from here.

In Kubernetes, when pods are scaled up or down, or Deployment config files are updated, etc - that helps pods create, update or delete - we know that no backups are necessary for stateless applications.

Control Loop in K8s

Recreating pods when they die or restarting them when the deployment file is updated, all these things are handled by the control loop mechanism of Controllers in K8s which matches the actual state with the desired state of an application. We don't need to worry after deploying the apps, Kubernetes manages the lifecycle of stateless applications using automation.

For stateful applications, K8s cannot automate these tasks, we need to manage its whole lifecycle while deploying it in a K8s cluster. As replicas of this type of application are not the same, they have their own state and they need to be synchronized i.e, there must be constant communication between these replicas to maintain consistency. We need to operate them manually. But it is very hard to update and manage these things in K8s.

What are K8s operators?

Operators are software extensions to Kubernetes that help in managing applications in K8s.

To automate the tasks for even stateful applications, we use Operators. Kubernetes operators are mainly used for StateFUL applications. Manual handling of tasks is not needed by humans.

Control Loop mechanism is also used here. Operators make use of CRDs - Custom Resource Definitions which is nothing but custom K8s components (K8s components are also known as K8s Resources or Objects and default K8s components are Pods, Service, ConfigMap, Deployment, etc). Using CRDs, users create Custom Resources(CRs). K8s don't know what to do with CRDs, so in addition to these components, it uses Controller to automate the lifecycle of the application.

Operators combine CRDs and concepts used in controllers to provide automation.

To create an operator, one should have knowledge of business logic like installing, running, and updating that specific application (like Elasticsearch, Postgres, Prometheus, Mysql). There are several operators already present but if you want to create your own we can use Operator SDK built by Red Hat.

Thank you for reading this blog! If you liked it, please do share and leave a like below! ๐Ÿ˜‡

0
Subscribe to my newsletter

Read articles from R Chan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

R Chan
R Chan

Passionate about learning technical stuff ๐Ÿ’ป. Using this platform to share what I learn each day as a software developer ๐Ÿ˜‡.