Skip to content

Room 45

OPERATORS


The Automation Engine

  • Operators encode operational knowledge into software. They use CRDs + controllers to manage complex applications.
  • Deploy a sample operator and interact with its custom resources.

📜 Mission Briefing

  1. Study the operator pattern: CRD + Controller + Reconciliation Loop.
  2. Apply operator-crd.yaml - defines a ManagedApp CRD.
  3. Apply operator-controller.yaml - deploys a simple controller.
  4. Create a ManagedApp resource - the controller should create a Deployment automatically.
  5. Check the controller logs for the password: operator.

Key Commands
Command Purpose
kubectl get crd List CRDs
kubectl get managedapps List operator’s CRs
kubectl logs deploy/operator-controller Controller logs

How Operators Work
# Operator Pattern:
#
# 1. CRD: Define your API (desired state)
#    apiVersion: apps.example.com/v1
#    kind: ManagedApp
#
# 2. Controller: Watch for changes, reconcile
#    Watch(ManagedApp) → Create/Update/Delete → Deployment, Service, ConfigMap
#
# 3. Reconciliation Loop:
#    Observe → Compare (desired vs actual) → Act → Repeat

# Operator Frameworks:
# - Operator SDK (Go, Helm, Ansible)
# - kubebuilder (Go)
# - Metacontroller (JavaScript/Python hooks)
# - KUDO (Declarative operators)
# - shell-operator (Bash/Python)

# Simple controller pseudocode:
# while true:
#   desired = get_custom_resource("ManagedApp")
#   actual = get_deployment(desired.name)
#   if actual != desired:
#     create_or_update_deployment(desired)
#   sleep(30)
# Operator CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: managedapps.apps.example.com
spec:
  group: apps.example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                image:
                  type: string
                replicas:
                  type: integer
                port:
                  type: integer
  scope: Namespaced
  names:
    plural: managedapps
    singular: managedapp
    kind: ManagedApp
# Install Operator SDK (optional)
# brew install operator-sdk

# Scaffold a Go operator
# operator-sdk init --domain=example.com --repo=github.com/my/operator
# operator-sdk create api --group=apps --version=v1 --kind=ManagedApp

# Build and deploy
# make docker-build docker-push IMG=my-registry/operator:v1
# make deploy IMG=my-registry/operator:v1

Hints

Hint 1

kubectl apply -f operator-crd.yaml
kubectl apply -f operator-controller.yaml
kubectl apply -f managed-app.yaml

Hint 2

Check the controller logs:

kubectl logs deploy/operator-controller | grep password

Hint 3

The password is operator.


🔓 Unlock Room 46

openssl enc -aes-256-cbc -d -a -pbkdf2 \
        -in ../room_46/README -out ../room_46/README.txt -pass pass:PASSWORD
cat ../room_46/README.txt