Working with Operators
1. Understanding Operator Pattern
Operator Loop
CR (desired) → Operator (controller) → reconcile → real resources → status
↑__________ watch (informer) __________|
| Component | Role |
| CRD | API type |
| Controller | Reconciliation loop |
| Domain Knowledge | Day-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
| Resource | Use |
| CatalogSource | Index of available operators |
| Subscription | Track upgrade channel |
| ClusterServiceVersion | Operator metadata + deployment |
| OperatorGroup | Multi-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
| Check | Command |
kubectl get csv -n operators | OLM operator state |
kubectl get CR -o yaml | yq .status | CR-level status |
kubectl get events | Reconcile errors |
8. Troubleshooting Operators
| Symptom | Cause |
| CR stuck Pending | RBAC missing for child resources |
| Reconcile loop crash | Bad CR spec; check operator logs |
| CSV failed | CRD 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.