Skip to content
tezvyn:

Kubernetes Operators: SREs in a Box

Source: kubernetes.ioHardHow cards are made

Kubernetes Operators: SREs in a Box

Think of an Operator as an automated site reliability engineer for your app, encoding human knowledge into software. It's used to manage complex stateful applications like databases, automating tasks like backups and upgrades.

Why it exists

Kubernetes provides powerful building blocks like Deployments and StatefulSets, but they are generic. They don't understand the specific operational needs of a complex application like a clustered database. How do you perform a coordinated upgrade, take a backup, or resize a cluster? The Operator pattern was created to automate this application-specific operational knowledge.

The mental model

An Operator is an automated site reliability engineer (SRE) for your application. It's a program running in your cluster that has deep, domain-specific knowledge about one piece of software. You tell it the desired state—"I want a 3-node Postgres cluster with daily backups"—and the Operator does whatever is necessary to make that happen and keep it that way.

How it works

An Operator combines two key Kubernetes concepts. First, a Custom Resource Definition (CRD) extends the Kubernetes API, creating a new object type, like PostgresCluster. Second, a custom controller (the Operator itself) watches for these new objects. When you create a PostgresCluster resource, the controller's reconciliation loop kicks in. It creates the low-level resources (StatefulSets, Services, ConfigMaps) and continuously monitors them to ensure the actual state matches the desired state you defined.

When to use it

Use the Operator pattern for managing complex, stateful applications that require specialized lifecycle management. This includes databases (etcd, Prometheus), message queues (Kafka), and other infrastructure components you want to run on Kubernetes as a managed, cloud-like service. It's for when you want to provide a simple, declarative API for a complex system.

When not to use it

Avoid Operators for simple, stateless applications. A standard Deployment or Job is far simpler to manage and understand. Building and maintaining an Operator is a significant engineering investment. Using one for a basic web application is a classic case of over-engineering and introduces unnecessary complexity.

One canonical example

The Prometheus Operator is a prime example. Instead of manually configuring dozens of YAML files for Prometheus, Alertmanager, and their targets, you create a simple Prometheus custom resource. The Operator then automatically deploys and manages the entire monitoring stack, even reconfiguring it when new services that need monitoring are deployed to the cluster.

Interview question

Which scenario best exemplifies the intended use case for a Kubernetes Operator?

  • a.Orchestrating a basic web server using standard Deployment and Service objects.
  • b.Managing a distributed database cluster with automated scaling and disaster recovery.Correct
  • c.Deploying a stateless API gateway with high availability requirements.
  • d.Running a one-off data processing task on a schedule.
Why?

Operators are designed for complex, stateful applications like databases that require specialized lifecycle management, automating tasks such as scaling and disaster recovery. For simpler, stateless applications or one-off tasks, standard Kubernetes resources like Deployments or Jobs are more appropriate and avoid over-engineering.

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