Summary - Operator
- Docker & Kubernetes course
- Expert
- Lesson 18/47
- 5 min
Combine CRD and reconcile to describe an operator.
Summary: operators
In this group:
- Operator = CRD + a controller containing operational knowledge; it manages the app after installation too.
- Reconcile is idempotent: read the custom resource, create/conform the child objects, write the status, requeue if needed.
ownerReferencesenable garbage collection and triggering; finalizers clean up external resources.- Operator SDK/Kubebuilder:
init,create api,make manifestsfrom markers,make install/run/deploy. - The user only interacts with the custom resource;
status.conditionsandkubectl waitreport readiness.
kubectl apply -f yedek.yaml
kubectl wait --for=condition=Ready yedek/magaza-gece -n magazaPractice Inspect a stuck object
Write three commands: print the finalizers of the magaza-gece Yedek in magaza with jsonpath='{.metadata.finalizers}'; show the last 20 lines of the operator's logs from deploy/yedek-operator-controller-manager in yedek-operator-system; list the pods in yedek-operator-system.
Starter code
# buraya yazSample solution
kubectl get yedek magaza-gece -n magaza -o jsonpath='{.metadata.finalizers}'
kubectl logs -n yedek-operator-system deploy/yedek-operator-controller-manager --tail=20
kubectl get pods -n yedek-operator-systemExpected output
["ornek.com/s3-temizle"]
ERROR S3 temizliği başarısız {"Yedek": "magaza/magaza-gece", "error": "AccessDenied"}
NAME READY STATUS RESTARTS
yedek-operator-controller-manager-6d9f8c7b5-x2k9p 1/1 Running 0
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 If a custom resource gets stuck in Terminating while being deleted, what is the likely cause?
- The disk is full
- The name is too long
- A printcolumn is missing in the CRD
- The operator that would remove the finalizer isn't running Correct answer
Explanation: The object isn't deleted until the finalizer list is empty.
2 Add a marker for cleanup before deletion.
metadata:
____: ["ornek.com/s3-temizle"]
metadata:
finalizers: ["ornek.com/s3-temizle"]
Explanation: Finalizers hold the deletion until the operator cleans up.
3 Match.
| Term | Meaning |
|---|---|
CRD |
Data model |
denetleyici |
Behaviour |
ownerReferences |
Garbage collection |
finalizer |
Deletion hook |