liveBook · Manning

Kubernetes operator

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

A Kubernetes operator is a software extension that uses custom resources and control-loop logic to automate application or service management.

A Kubernetes operator extends the API to manage an application or service. Its Custom Resource Definitions (CRDs) establish the resource types and fields; its controller defines how to manage those resources, automating tasks such as deployment, scaling, and healing. The operator is more than a CRD alone. section 5.4

A CRD is the definition of a resource type; a custom resource (CR) is an object created from that definition. Create the CRD before creating its CRs. For example, an operator can define a Cluster resource type, then respond when you create a particular Cluster object. section 5.4.3

To install and inspect an operator:

  • Apply its installation YAML with kubectl, or install it with Helm. The CloudNativePG installation YAML installs the operator and its CRDs; Helm installs CRDs by default unless --skip-crds is specified. section 5.4.2
  • Run kubectl get crds to confirm the definitions are present. Use kubectl api-resources --api-group=postgresql.cnpg.io to find their API resources, and kubectl explain clusters.postgresql.cnpg.io to inspect the Cluster schema. section 5.4.2
  • Check that the controller is running with kubectl get deployment -n cnpg-system cnpg-controller-manager. Installing resource definitions is not the same as creating a resource for the operator to manage. section 5.4.3
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: my-postgres-cluster
  namespace: default
spec:
  instances: 1
  storage:
    size: 1Gi

This Cluster CR requests one Postgres instance with 1Gi of storage in the default namespace. Its apiVersion and kind identify the operator-provided resource type. section 5.4.3

Save that manifest as postgres-cluster.yaml and run kubectl apply -f postgres-cluster.yaml. Then run kubectl get cluster my-postgres-cluster: the example reports one ready instance and a healthy cluster. kubectl describe cluster my-postgres-cluster shows more status detail, while kubectl get pods confirms the instance is running. This one-instance exercise verifies operation; it does not demonstrate a highly available configuration. section 5.4.3

For CKA preparation, practice the general workflow rather than memorizing a particular operator: install it, identify its CRDs, inspect the expected fields, create a CR, and verify the resulting state. The exam does not require knowledge of one specific operator. section 5.4 section 9.3.4

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Works through installation, CRD inspection, custom resource creation, and verification; stops short of implementing an operator controller.
Examples
Uses CloudNativePG installation commands, a Postgres Cluster YAML manifest, and kubectl status checks.
What it assumes
Assumes basic kubectl, Deployment, and Kubernetes API familiarity while explicitly distinguishing CRDs from custom resources.
What you can do after
Operate/configure it by installing an operator, inspecting its CRDs, creating a custom resource, and checking the resulting cluster state.
How it connects
Connects Custom Resource Definitions, custom resources, controllers, Deployments, and the Kubernetes API.

Also explained in

Compare how 7 books explain Kubernetes operator →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.