Working with Operators

1. Understanding Operator Pattern

Operator Loop

CR (desired) → Operator (controller) → reconcile → real resources → status
                  ↑__________ watch (informer) __________|
        
ComponentRole
CRDAPI type
ControllerReconciliation loop
Domain KnowledgeDay-2 ops (backup, upgrade)

2. Installing Operators

helm install postgres-operator postgres-operator-charts/postgres-operator \
  -n operators --create-namespace
# Or via OLM
kubectl apply -f https://operatorhub.io/install/postgres-operator.yaml

3. Using Operator Lifecycle Manager

curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.28.0/install.sh | bash -s v0.28.0
ResourceUse
CatalogSourceIndex of available operators
SubscriptionTrack upgrade channel
ClusterServiceVersionOperator metadata + deployment
OperatorGroupMulti-ns scope

4. Creating Custom Resources

apiVersion: acid.zalan.do/v1
kind: postgresql
metadata: { name: acid-minimal, namespace: prod }
spec:
  teamId: acid
  numberOfInstances: 3
  postgresql: { version: "16" }
  volume: { size: 10Gi }

5. Viewing Operator Logs

kubectl logs -n operators deploy/postgres-operator -f
kubectl logs -n operators -l name=postgres-operator --tail=200

6. Updating Custom Resources

kubectl edit postgresql acid-minimal
kubectl patch postgresql acid-minimal --type=merge \
  -p '{"spec":{"numberOfInstances":5}}'

7. Monitoring Operator Status

CheckCommand
kubectl get csv -n operatorsOLM operator state
kubectl get CR -o yaml | yq .statusCR-level status
kubectl get eventsReconcile errors

8. Troubleshooting Operators

SymptomCause
CR stuck PendingRBAC missing for child resources
Reconcile loop crashBad CR spec; check operator logs
CSV failedCRD conflicts; existing version installed

9. Upgrading Operators

helm upgrade postgres-operator postgres-operator-charts/postgres-operator --version 1.12.0
# OLM: change channel/version in Subscription

10. Deleting Operators

kubectl delete subscription postgres-operator -n operators
kubectl delete csv postgres-operator.v1.11.0 -n operators
helm uninstall postgres-operator -n operators
Warning: Removing operator does not remove existing CRs or underlying workloads — delete those first to clean up.