Once I register the crd into the k8s cluster, I can use .yaml to create it, without operator running. Then What happends to these created resouces?
I have seen the
Reconciler
of operator, but it's more like an async status transfer. When we create a pod, we can directly get the pod ip from the create result. But it seems that I didn't find a place to write myOnCreate
hook. (I just see somevalidate
webhook, but never see a hook that be called when creation request made, defines how to create the resourse, and return the created resourse info to the caller ).If my story is that for one kind of resource, in a time window, all coming creation will multiplex only one pod. Can you give me some advice?
CodePudding user response:
That's a big story for kubernetes crd
/controller
life cycle, I try to make a simple representation.
- After register a new CRD, and create CR,
kube-api-server
do not care if there is a relatedcontroller
existed or not. see the process:
That's means the resource(your CR) will be store to etcd, has no business of your controller
- ok, let talk about your controller. your controller will setup a
list/watch
(actually a long live http link) to theapi-server
and registerhook
(what you ask, right?) for different event:onCreate
,onUpdate
andonDelete
. Actually you will handle all event in your controller'sreconcile
(remember kubernetes reconcile's responsibility: move current state to desired state). see the diagram:
- For the
list/watch
link in yourcontroller
, you need set different link for different kind of resource. for example: if you care about event forpod
, you need setpod
list/watch
or care about deployment, and set adeployment
list/watch
...