Have you ever imagined what happens behind the scenes when you create a pod in Kubernetes using the manifest yaml? I will try to tell the story of a pod, from the manifest yaml to its journey to becoming an actual running pod on the node.
This story will need a little bit of background regarding Kubernetes and how a pod is created. I have provided links to Kubernetes docs and an external link to Github to study more details regarding the topic. I would first recommend going through the blog to understand the journey, and then you can get into the details.
To create a pod in Kubernetes, we first write its manifest yaml, which actually contains quite a bit of information. This information on the manifest yaml is nothing but a guideline on what an actual running pod should look like. You can consider this analogous to creating a house map design before building the actual house. The house map is read by a several people who are involved in building the house as specified in the map design. The story of creating a pod I similar— here, instead of several people, there are some Kubernetes components that help the pod towards its running state.
I will paste a very simple pod manifest yaml here to elaborate on this example in simple terms. Whether the pod manifest is very basic or complex, what happens under the hood is the same. Take a look at the following pod manifest yaml.
apiVersion: v1 kind: Pod metadata: name: example-pod labels: env: story-telling spec: containers: - name: example-pod image: sonasingh46/node-web-app:latest ports: - containerPort: 8000 |
Part 1: (Kube-apiserver:Authentication) Authentication to kube-apiserver to submit pod manifest
It should be noted that there are several authentication modules in kube-apiserver, and if any one module passes the request the authentication is completed.
To learn more about how authentication works in kube-apiserver, please review the following document:
https://kubernetes.io/docs/reference/access-authn-authz/controlling-access/#authentication
In short, we can summarise that a normal user account must be authenticated to kube-apiserver and submitted to the pod manifest to the kube-apiserver for further steps to be taken so that a pod can be created successfully.
Part 2: (Kube-apiserver: Authorization) Checking the authority of the user to create a pod.
It should be noted that there are several authorization modules in kube-apiserver. If any one module authorizes the request then it can proceed.
To learn more about authorization in kube-apiserver, please go through the following link :
https://kubernetes.io/docs/reference/access-authn-authz/controlling-access/#authorization
In short, we can summarise by saying that once the pod request passes the authentication layer, the request is checked for authorization. Again, if the request passes here further steps are taken.
Part 3: (Kube-apiserver: Admission Control) Admitting a pod to the database
It should be noted that if any one of the admission control modules in the list rejects the request, the entire request is rejected and an error is returned.
Great! At this point of time, the pod object is persisted to the database if all the above steps specified passes successfully.
In general, for most of the api request to kube-apiserver, the above three specified sections are executed.
Part 4: (Scheduler) Scheduling the pod to a node
To learn more about how scheduling in Kubernetes works, please review the following link:
https://github.com/kubernetes/community/blob/master/contributors/devel/scheduler.md
Part 5: (Kubelet) Running the pod to the selected node
Wow! This was a high-level picture of a pod’s journey in Kubernetes. I have tried to keep it simple and frame the content based on my experiments and asking questions on Kubernetes slack.
If you feel it needs any correction or feedback, feel free to comment.
Also, you can review the following link to learn more specifics of what happens in each part specified above.
https://github.com/jamiehannaford/what-happens-when-k8s
I hope this helps! Thank you and see you in the next post!
This article was first published on Dec 14, 2018 on MayaData's Medium Account