An Operator is an application-specific controller that extends the Kubernetes API to create, configure and manage instances of complex stateful applications on behalf of a Kubernetes user. It builds upon the basic Kubernetes resource and controller concepts, but also includes domain or application-specific knowledge to automate common tasks better managed by computers.
We use Operators because managing stateful applications, like databases, caches and monitoring systems, is a big challenge, especially at massive scale. These systems require human operational knowledge to correctly scale, upgrade and reconfigure while at the same time protecting against data loss and unavailability.
So, we take the same operational knowledge capable of managing a relatively small cluster and encode it into the software to apply. The Operator is then able to leverage the powerful Kubernetes abstractions to run and manage the application correctly, and at scale.
An Operator extends the Kubernetes API through the third party resources mechanism, enabling users to create, configure and manage applications. Like Kubernetes’ built-in resources, an Operator doesn’t manage just a single instance of the application, but multiple instances across the cluster.
The etcd Operator, for example, simulates human operator behaviors in three steps. First, it observes the current cluster state by using the Kubernetes API. Second, it finds and analyzes the differences between the desired state and current state. Last, it fixes those differences through one or both of the etcd cluster management API or the Kubernetes API. Let's say we have an etcd cluster of 3 members, and one of them happens to be down. The etcd Operator continually compares the desired state (3 members) with the current state (2 members). In this circumstance, the Operator heals the cluster by replacing the dead member with a new one. Now the etcd cluster is back to a healthy state.