What is a Kubernetes operator?
A Kubernetes operator is a method for application packaging and deployment that extends Kubernetes' capabilities to manage more complex, stateful workloads. Examples of these workloads include databases, distributed systems that use quorum mechanisms and applications that cannot easily be reconfigured in a single step. Even with stateless workloads, operators help shape a consistent definition of an application on Kubernetes.
Benefits and capabilities of Kubernetes operators
Kubernetes operators codify accumulated best practices and operational procedures into software running on Kubernetes. What was previously managed by scripts and site reliability engineers (SREs) outside a cluster is now governed by custom Kubernetes extensions running on the cluster with the managed workload. Operator capabilities include complex installation and update routines, lifecycle events -- such as backups, restores, failovers and failbacks -- and metrics-driven scaling.
Whereas most Kubernetes-driven development focuses on stateless, front-end and API-centric applications, operators bring the rest of the stack into the environment. This simplifies configuration and management as Kubernetes becomes a crucial aspect of portability for IT and engineering.
Operators also support higher uptime and lower operational labor by automatically remediating configuration drift. Because this can be achieved using Kubernetes' own extension mechanisms, the method is platform independent and driven by the Kubernetes community.
How Kubernetes operators work
Operators connect to the Kubernetes API and watch for relevant events. They act as custom Kubernetes controllers, introducing their own object types in the cluster that constantly compare the desired state with the actual state.
The desired state is declared in YAML and expressed by the user creating Kubernetes objects as a custom resource definition (CRD). The operator runs through its loop whenever such objects appear, are updated or are deleted. Operators run as pods on the cluster.
Although the cluster administrator is responsible for installing operators, they are built to aid the end user. Operators are integrated with Kubernetes such that users can continue to use kubectl tooling and deal with complex software as they would when using more primitive built-in Kubernetes resources.
Kubernetes operators vs. Helm charts
Helm is currently the predominant package manager for Kubernetes. This open source tool, maintained by the Cloud Native Computing Foundation, templates Kubernetes components and bundles them into packages -- known as charts -- that can be versioned and shipped to clusters for deployment.
Operators represent an evolution of this concept, taking it a step further to include the stages of the application lifecycle after initial deployment. As such, Kubernetes operators complement Helm charts. Users can build operators from Helm charts without writing any code by using the Kubernetes operator software development kit (SDK).