A pod is the smallest deployable unit that you can create and manage in Kubernetes.
But how to create a pod, is just as simple as running kubectl run my-pod --image=nginx
. But this simple task undergoes a complicated workflow that touches a lot of components in the cluster.
So what happens exactly,
First things first, you need to tell the API server that you need a pod to be created. So you use kubectl to send YAML (pod manifest) to the API. API server receives the request and saves the definition to the database which is default etcd.
etcd is the key value store in Kubernetes that stores the entire state of the cluster. Now we have asked API Server to create a pod, so etcd will now store the Pod. At this point, Pod is stored in etcd. And it will be in the pending state now.
Now Scheduler sees the pending state and checks the nodes to make the decision to schedule the pod to the node. No pod is created until now, it just schedules the pod to a node.
On each worker node, we have a kubelet which is more of an interface between the control plane and components in the worker node. The kubelet is the scheduled node now retrieves the pod template and starts creating it.
The kubelet now asks CRI (container runtime interface) to create a container (one which our pod def contains).
The kubelet also asks CNI ( container network interface) to attach the container to the network. Now CNI assigns an IP address to the POD.
Also, kubelet checks any probes that are defined.
Now we have an IP address at which our pod is running. The last job of the kubelet is to report back to the Control plane. So Kubelet reports the IP address to the control Plane.
The POD is now created and is finally marked as running.
This shows the high-level workflow of what pod creation goes through, but please note these steps might have missed some minute details.
That's a wrap!!!
Hope you learned something. Let me know your feedback and if you have any suggestions or questions, you can connect with me on Twitter.
Till next, Happy kubectl'ing