K8S Resource CRUD Workflow
Last updated
Last updated
Deployment controller (inside of kube-controller-manager)
Notices (through a deployment informer) that user creates a deployment
Create a replicaset
ReplicaSet controller (inside of kube-controller-manager)
Notices (through a replicaSet informer) that the newly created replicaSet
Create Pod objects
Scheduler which is also a controller (inside kube-scheduler binary)
Notices (through a pod informer) that the Pod object with empty spec.nodename
Put the Pod object into scheduling queue
The meanwhile the kubelet (is also a controller)
Notices the Pod object (through a pod informer) that the Pod object's spec.nodename (which is empty) does not match its node name.
Ignore the Pod object and goes back to sleep
Scheduler
Takes the Pod object out of its work queue
Schedule to a node which has enough resource by updating its spec.nodename
Write it to API Server
kubelet wakes up by the Pod object update events
It compares the spec.nodename (in this case, we assume it matches node name)
Start the containers of the Pod object
Update the Pod object status with the information indicates that the containers have been started
Report back to API Server
ReplicaSet controller notices the changes of the Pod object, but has nothing to do
If Pod object terminates, kubelet notices the change
Get the Pod object from API Server
Change its status to "Terminated"
Write it back to API Server
The replicaSet controller notices the terminated pod and decides that this pod must be replaced
It deletes the terminated pod on the API server and creates a new one
And so on
They are instantiate by the custom controller code. The following is the sample-controller code.
When InformerFactory get instantiated, the reflector, informer and indexer are instanciated accordingly. When calling InformerFactory.Start(), the Informer controller and Reflector are running. Indexer is wrapped as the FooLister()
in the sample-controller example.