Automating Multi-Tenant Applications with Kubernetes Operators

  • June 10, 2021

Automation in the cloud is mandatory. Beyond being mandatory, automation makes business sense. The complexity, size, and dynamics of today’s business world, especially startups, make manual operations an undesirable choice due to a lack of reliability, speed, and consistency. Much automation is achieved using Infrastructure as code. However, there may be cases where Infrastructure as code does not work. This is where Infrastructure-as-software comes in. It can give you even broader access to automation which applies to tools like Kubernetes. 

Kubernetes may be something your organization is considering or a tool you already have in use. To manage automation on a Kubernetes-based platform, operators are an option you will want to consider. Traditionally, cloud or DevOps engineers perform upgrades calling some automation local from their workstations or from a CI/CD pipeline. This approach doesn’t work in environments where you need a more dynamic and flexible approach. For example, when you need to update your infrastructure/platform constantly. Such is the case with multi-tenant applications, where each new tenant requires new services running. Kubernetes operators can help to optimize these kinds of processes.


What’s an Operator?

Kubernetes operators were introduced as an implementation of the Infrastructure as a software concept. By using them, you can abstract the deployment of applications and services in a Kubernetes cluster.

Operators have domain and application-specific knowledge that allows them to automate some tasks, which allows them to extend the Kubernetes API. By doing so, operators provide users new ways to manage and orchestrate objects and abstract their complexity. In short, an operator provides you with an API to specify the desired state while at the same time taking care of the details to reach that state. 

Kubernetes operators are able to leverage two concepts to abstract complex orchestration. 

Custom Resources 

The first concept leveraged by operators is Custom Resources that extend to the API, adding new kinds of objects. While a resource is an endpoint in Kubernetes, a custom resource is one not shipped with Kubernetes but installed on a cluster after its creation. 

Custom Controllers

Secondly, operators leverage Custom Controllers to manage custom and non-custom objects according to the information stored in the custom resource. This allows you to extend the behavior without having to alter the Kubernetes code.


Operators for Multi-tenant Apps

A multi-tenant app managed by an operator has some unique characteristics. An operator (human or not) is responsible for some tasks when a new client (tenant) creates an account or closes an account. They know everything about the application, including what services are required to keep it up and running and any additional actions that need to be triggered. 

With Kubernetes, you can fully automate the deployment and running of your workloads and automate how that is done. When it comes to multi-tenant apps, our operators must be smart enough to manage several tasks. All in all, there are many things a Kubernetes operator can do for multi-tenant apps, including but not limited to: 

  • Managing one or more container per tenant.
  • Initializing a database or another service for each new user
  • Set up backups for new tenants

By design, operators have all of the considerations for any specific Kubernetes application. They will ensure that every part of its lifecycle is integrated right into the framework and is ready to be used when needed. Thus, operators are an essential piece of software for automation. 

When you know how to manage the right tools the right way, you can take full advantage of the Cloud and Kubernetes. Traditional Infrastructure as Code can be a bit limited. K8s Operators, as an example of Infrastructure as Software, on the other hand, can provide better benefits in some cases.


Written by: Stas Serebrennikov
General corrections and edition: Diego Woitasen