DevOps & Containers

Kubernetes Operators Explained: Automating Day-2 Operations

By NileVPS Team · Published · 5 min read

اقرأ المقال بالعربي

Deploying a stateless web app on Kubernetes is straightforward: a Deployment, a Service, maybe an Ingress. Running a database, a message broker or a certificate manager is a different story. These systems need backups, failover, version upgrades and careful configuration changes, the kind of work an experienced administrator does by hand. A Kubernetes operator captures that operational knowledge in software, so the cluster can perform those tasks automatically. This article explains how operators work, shows a real example and helps you decide when one is worth adding.

The Building Blocks: Controllers and Reconciliation

Kubernetes is built around a simple loop. You declare the desired state (for example, "three replicas of this pod"), and controllers continuously compare it to the actual state and act to close the gap. The Deployment controller creates or deletes pods; the node controller notices failed nodes. This process is called reconciliation, and it never stops: if someone deletes a pod by hand, the controller recreates it.

An operator applies exactly the same pattern to an application that Kubernetes knows nothing about. It has two parts:

  1. A Custom Resource Definition (CRD) that adds a new object type to the Kubernetes API, such as PostgresCluster or Certificate.
  2. A custom controller that watches those objects and does whatever is needed to make reality match them: creating StatefulSets, Services and Secrets, running backups, promoting replicas and more.

The result is that you manage complex software with the same kubectl apply workflow you use for everything else.

What a Custom Resource Looks Like

Here is a PostgreSQL cluster managed by the CloudNativePG operator. Instead of writing StatefulSets, replication config and failover scripts, you declare what you want:

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: app-db
spec:
  instances: 3
  storage:
    size: 20Gi

The operator creates one primary and two replicas, configures streaming replication, exposes read-write and read-only Services, and promotes a replica if the primary fails. Changing instances or the PostgreSQL image triggers a controlled scale or rolling upgrade.

You can explore what operators have added to a cluster with:

kubectl get crd                    # list custom resource definitions
kubectl api-resources --api-group=postgresql.cnpg.io
kubectl explain cluster.spec       # read the schema of a custom resource
kubectl get clusters -A            # list objects of the new type

Common Operators You Will Meet

OperatorWhat it manages
cert-managerTLS certificates from Let's Encrypt and other issuers, with automatic renewal
Prometheus OperatorPrometheus, Alertmanager and scrape targets through ServiceMonitor objects
CloudNativePGPostgreSQL clusters, backups and failover
StrimziApache Kafka clusters, topics and users
RookCeph storage inside the cluster

Most are installed with a Helm chart or a single manifest, and many are listed on OperatorHub.io.

Operator Capability Levels

The Operator Framework describes five maturity levels, which are a helpful way to judge what an operator really does:

  1. Basic install: automated deployment and configuration.
  2. Seamless upgrades: upgrades of the operator and the managed application.
  3. Full lifecycle: backups, restore and failure recovery.
  4. Deep insights: metrics, alerts and log processing.
  5. Auto pilot: automatic scaling, tuning and anomaly handling.

An operator that only installs software is little more than a Helm chart. The real value starts at level 3, where routine and emergency tasks are handled for you.

Writing Your Own Operator

If you run an in-house application with repetitive operational tasks, you can build an operator. Popular tools include:

  • Kubebuilder and Operator SDK (Go), which generate the CRD, controller skeleton and tests.
  • Kopf (Python), lighter and quick for small automations.
  • Operator SDK with Ansible or Helm, which wraps existing playbooks or charts.

Good design rules: keep the reconcile function idempotent (running it twice must be safe), store progress in the resource's status field, use owner references so child objects are cleaned up automatically, and never assume the previous run finished.

When an Operator Is Worth It, and When It Is Not

Use an operator when:

  • The software is stateful and needs coordinated failover, backups or upgrades.
  • A well-maintained, actively developed operator already exists.
  • You run several instances and want consistent management.

Think twice when:

  • You run a single small cluster or one VPS. A managed backup script with pg_dump and a systemd timer may be simpler and easier to understand.
  • The operator is unmaintained. It runs with broad cluster permissions, so review its RBAC and project activity.
  • Nobody on the team understands what it does. Automation you cannot debug becomes a risk during an incident.

If you are just getting started, learn what Kubernetes is and how k3s runs on a VPS first, then add operators one at a time.

Practical Tips

  • Install operators into their own namespace and pin chart versions.
  • Read the upgrade notes: CRD changes are not always handled by helm upgrade.
  • Back up custom resources along with application data; tools like Velero can do both.
  • Watch the operator's own logs with kubectl logs -n <namespace> deploy/<operator>.

A small three-node cluster on VPS instances is a realistic place to test operators safely before production; see our pricing.

FAQ

What is the difference between a Helm chart and an operator?

A Helm chart renders and installs manifests once per install or upgrade. An operator runs continuously inside the cluster and reacts to changes and failures, handling tasks such as failover and backups that a chart cannot perform.

Do operators replace database administrators?

No. They automate routine and well-understood tasks, but someone still needs to plan capacity, tune queries, verify backups and handle unusual failures. Operators reduce toil; they do not remove responsibility.

Are operators safe to run?

Well-known operators are widely used, but they usually need broad permissions. Install them from official sources, review the RBAC they request, keep them updated and test upgrades on a non-production cluster first.

Related guides