Deployment
controller (inside kube-controller-manager):- Notices (through a deployment informer) that user creates a
Deployment
object. - Create a
ReplicaSet
object.
- Notices (through a deployment informer) that user creates a
ReplicaSet
controller (inside kube-controller-manager):- Notices (through a replicaSet informer) that the newly created
ReplicaSet
object. - Create
Pod
objects.
- Notices (through a replicaSet informer) that the newly created
kube-scheduler
which is also a controller (inside kube-scheduler binary):- Notices (through a pod informer) that the
Pod
objects with emptyPod.spec.nodename
. - Puts the
Pod
objects in the scheduling queue.
- Notices (through a pod informer) that the
- The meanwhile the
kubelet
(is also a controller):- Notices the
Pod
objects (through a pod informer) that thePod.spec.nodeName
(which are empty) does not match its node name. - Ignores the
Pod
objects and goes back to sleep
- Notices the
kube-scheduler
:- Dequeues the
Pod
object from its work queue. - Schedules it to the node has enough resource by updating
Pod.spec.nodeName
. - Sends the updates to API Server.
- Dequeues the
kubelet
wakes up by the Pod object update events:- Compares the
Pod.spec.nodeName
(in this case, we assume it matches node name). - Talks to container runtime via
CRI
to start the containers of thePod
objects. - Updates the
Pod
objects status with the information indicates that the containers have been started. - Report back to API Server.
- Compares the
- Container runtime interacts with K8S network plugin via
CNI
to create the network for the pod:- Add: the
Pod
object is created, configure the network for thatPod
object. - Delete: the
Pod
object is deleted, cleanup the network resource for that `Pod object. - Check: can be called periodically to make sure everything is good.
- Add: the
CNI
will createveth
pair and assign IP address to thatPod
object.
ReplicaSet
controller reconciles thePod
objects.- If Pod object terminates unexpectedly, kubelet notices the change:
- Get the Pod object from API Server.
- Change its status to "Terminated".
- Send the updates back to API Server.
- The
ReplicaSet
controller notices the terminated pod and decides that this pod must be replaced:- It deletes the terminated pod and creates a new one.
- And so on