Skip to content
Tutorials Center
My learning

Topics

Lesson 28 of 37 ยท Security and Operators

Operators and the Operator Lifecycle Manager

Understand Operators in OpenShift: custom resources and controllers, OperatorHub, OLM subscriptions, channels, install modes, approval strategy and cluster operators.

OpenShift 4 is built from Operators. The platform itself (networking, ingress, authentication, the registry, monitoring) is managed by cluster operators, and you add databases, message brokers, service meshes and many other products by installing Operators from OperatorHub. An Operator is a controller that encodes the knowledge of a human administrator: how to install, configure, back up and upgrade a piece of software.

Nothing runs on the cluster here: the commands and YAML are read-only. The Python stand-ins model the reconciliation loop and version upgrade path.

Custom resources and controllers

Kubernetes lets you extend its API with a CustomResourceDefinition (CRD). A CRD adds a new kind, say PostgresCluster. You then write a short desired state:

YAML
apiVersion: postgres.example.com/v1
kind: PostgresCluster
metadata:
  name: shop-db
spec:
  instances: 3
  version: "16"
  storage: 20Gi

An Operator runs a controller that watches these objects and works until reality matches: it creates StatefulSets, Services, Secrets and backups, replaces failed members and performs upgrades. The loop is always the same: observe, compare with desired, act, repeat. This is called reconciliation.

Python Stand-in: a reconcile loop

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Cluster operators

The platform's own components report through ClusterOperator objects:

Terminal
oc get clusteroperators
oc describe clusteroperator ingress

Columns to read: AVAILABLE (works), PROGRESSING (changing, for example during an update), DEGRADED (something is wrong). A healthy cluster shows True False False everywhere. A degraded operator is the first thing to check when something misbehaves.

OperatorHub and OLM

The Operator Lifecycle Manager (OLM) installs and upgrades the operators you add. In the web console go to Operators > OperatorHub, pick an operator, choose the options, and install. The same thing from YAML uses three objects:

YAML
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
  name: shop-og
  namespace: shop
spec:
  targetNamespaces: [shop]
---
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: postgresql-operator
  namespace: shop
spec:
  channel: stable
  name: postgresql-operator
  source: certified-operators
  sourceNamespace: openshift-marketplace
  installPlanApproval: Manual
  • CatalogSource: a catalog of operators (redhat-operators, certified-operators, community-operators, and your own mirrored catalogs).
  • OperatorGroup: which namespaces the operator watches (a single namespace, several, or all).
  • Subscription: "keep me on this channel of this operator".
  • InstallPlan: the concrete list of steps for one version. With installPlanApproval: Manual an admin must approve it, giving you control over upgrades.
  • ClusterServiceVersion (CSV): the operator's version and metadata; its phase should be Succeeded.
Terminal
oc get subscription,installplan,csv -n shop
oc patch installplan install-abcde -n shop --type=merge -p '{"spec":{"approved":true}}'

Use Manual approval for production so an operator upgrade never lands unreviewed. Use Automatic in development to stay current.

Channels and upgrades

An operator publishes versions into channels such as stable, fast or v2.4. The subscription follows one channel, and OLM computes an upgrade path from the installed version using replaces and skips metadata, so you cannot jump to a version that skips a required step.

Python Stand-in: pick the upgrade path

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Install modes and scope

An operator advertises which modes it supports: OwnNamespace, SingleNamespace, MultiNamespace and AllNamespaces. Cluster-wide operators go into openshift-operators with an all-namespaces OperatorGroup. A namespace-scoped install keeps one team's operator separate. Operators ask for RBAC through their CSV, so read what an operator requests before installing: it often needs broad permissions.

Removing an operator

Uninstalling an operator does not remove the resources it created. Delete your custom resources first (the operator cleans up the workloads), then the Subscription and CSV. Deleting the CRD deletes all custom resources of that kind, so be careful.

Terminal
oc delete postgrescluster shop-db -n shop
oc delete subscription postgresql-operator -n shop
oc delete csv postgresql-operator.v2.4.0 -n shop

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does an Operator's controller do?

    Operators watch their custom resources and continually act to make the cluster match them.
  2. 2. What does a Subscription with installPlanApproval: Manual give you?

    OLM creates the InstallPlan but waits until it is approved.
  3. 3. In oc get clusteroperators, which combination is healthy?

    Healthy operators are available, not changing and not degraded.
  4. 4. What happens to custom resources if you delete the CRD?

    Deleting a CRD removes every object of that kind, so delete operator-managed resources deliberately.

Summary

  • Operators = CRDs + controllers that automate running software.
  • Cluster operators run the platform; check them with oc get clusteroperators.
  • OLM installs add-on operators via CatalogSource, OperatorGroup, Subscription, InstallPlan and CSV.
  • Channels and the replaces graph define upgrade paths; use manual approval in production.
  • Delete custom resources before removing an operator or its CRDs.

Next: Persistent volumes and claims