Skip to content
tezvyn:
Menu

The Operator Pattern: A Robot SRE for Your App

Source: kubernetes.ioEasyHow cards are made

The Operator Pattern: A Robot SRE for Your App

The Operator pattern adds a custom, automated "robot SRE" to your Kubernetes cluster. It encodes human operational knowledge for a specific application, like a database, into software that handles complex tasks like upgrades, backups, and failovers…

Why it exists

Kubernetes is great at managing stateless apps, but complex stateful apps like databases require specific operational knowledge for tasks like backups, upgrades, and failovers. The Operator pattern was created to automate this domain-specific knowledge, which is difficult to express with standard Kubernetes objects alone.

The mental model

Think of an Operator as a robot Site Reliability Engineer (SRE) that lives inside your cluster. You give it the runbook for your application (e.g., "how to safely upgrade a Postgres cluster"), and it executes those steps automatically. It extends the Kubernetes API with custom resources, letting you manage your app declaratively, just like a built-in resource.

How it works

An Operator combines two key Kubernetes features. First, a Custom Resource Definition (CRD) defines a new object type, like kind: PostgresCluster. Second, a custom controller (the Operator itself, a program running in a Pod) watches for these new objects. When you create a PostgresCluster resource, the controller sees it and performs the necessary actions—creating StatefulSets, Services, and ConfigMaps—to bring the database to life. It then continuously monitors the state, reconciling any differences between your desired state and the actual state in the cluster.

When to use it

Use the Operator pattern for applications with a complex lifecycle that can't be managed by standard Deployments or StatefulSets. It's ideal for databases, message brokers, and monitoring systems that you want to run natively on Kubernetes with automated day-2 operations (like backups and scaling).

When not to use it

Do not build or use an Operator for a simple, stateless application. A standard Deployment and Service are far simpler and sufficient. Building a robust Operator is a significant engineering effort, and using a complex one adds operational overhead. A Helm chart is often a better choice for simple application packaging.

One canonical example

The Prometheus Operator. Instead of manually configuring Prometheus servers, you create a Prometheus custom resource. The Operator then automatically deploys and configures Prometheus. To monitor a new service, you just create a ServiceMonitor resource, and the Operator automatically updates the Prometheus configuration to start scraping it.

Interview question

What is the primary benefit of implementing the Kubernetes Operator pattern?

  • a.To provide a web-based dashboard for real-time monitoring of all cluster resources.
  • b.To eliminate the need for standard Kubernetes resources like StatefulSets and Deployments.
  • c.To simplify the deployment of simple, stateless applications using custom APIs.
  • d.To automate complex, domain-specific operational tasks for stateful applications.Correct
Why?

The Operator pattern is designed to automate complex, domain-specific operational knowledge for applications, especially stateful ones, acting as a 'robot SRE'. Option C is incorrect because the card explicitly states that Operators are not for simple, stateless applications, which are better managed with standard deployments or Helm charts.

Just read this? Test yourself on what you have been reading.

Read the original → kubernetes.io

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on kubernetes — each one lists the topics its interview covers.

See open roles