tezvyn:

Kubernetes Operators: SREs in a Box

AI-drafted, machine-checkedSource: kubernetes.ioadvanced
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.

Read the original → kubernetes.io

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.