Learning Library

← Back to Library

How Kubernetes Creates a Pod

Key Points

  • A pod creation request sent with `kubectl` first hits the kube‑API server, which authenticates the user and validates the request before persisting the desired pod definition to etcd, the cluster’s distributed source‑of‑truth datastore.
  • Writing the pod to etcd marks the pod as “created” in Kubernetes’s desired state, even though no containers are running yet; the system’s job is now to reconcile this desired state with the actual state.
  • The kube‑scheduler continuously polls the API server (roughly every five seconds) for unscheduled workloads, selects an appropriate compute node based on resource availability and policies, and updates the pod’s spec with the chosen node.
  • Control nodes (running the API server, scheduler, and other control‑plane components) manage the cluster, while compute nodes host the actual workloads; a production setup typically uses multiple control nodes for high availability.

Full Transcript

# How Kubernetes Creates a Pod **Source:** [https://www.youtube.com/watch?v=BgrQ16r84pM](https://www.youtube.com/watch?v=BgrQ16r84pM) **Duration:** 00:09:52 ## Summary - A pod creation request sent with `kubectl` first hits the kube‑API server, which authenticates the user and validates the request before persisting the desired pod definition to etcd, the cluster’s distributed source‑of‑truth datastore. - Writing the pod to etcd marks the pod as “created” in Kubernetes’s desired state, even though no containers are running yet; the system’s job is now to reconcile this desired state with the actual state. - The kube‑scheduler continuously polls the API server (roughly every five seconds) for unscheduled workloads, selects an appropriate compute node based on resource availability and policies, and updates the pod’s spec with the chosen node. - Control nodes (running the API server, scheduler, and other control‑plane components) manage the cluster, while compute nodes host the actual workloads; a production setup typically uses multiple control nodes for high availability. ## Sections - [00:00:00](https://www.youtube.com/watch?v=BgrQ16r84pM&t=0s) **Behind the Scenes: Pod Creation** - The speaker explains how a kubectl request is received by the kube‑API server, authenticated and validated, and then coordinated across control and compute nodes to instantiate a Kubernetes pod. - [00:03:11](https://www.youtube.com/watch?v=BgrQ16r84pM&t=191s) **Kubernetes Scheduler and Kubelet Overview** - The speaker explains how the scheduler regularly polls the API server to assign pending pods to nodes, and how each node’s Kubelet registers with the control plane, performs health checks, and creates or destroys workloads as directed. - [00:06:19](https://www.youtube.com/watch?v=BgrQ16r84pM&t=379s) **Kubernetes Scheduling and Controller Flow** - It explains that after the scheduler picks a node, the kube‑api server records the placement in etcd, the kubelet on that node creates the pod, and the controller manager monitors restart policies to ensure the desired state is maintained. - [00:09:30](https://www.youtube.com/watch?v=BgrQ16r84pM&t=570s) **Thanks, CTA, and Promotion** - The speaker thanks viewers, invites them to ask questions, encourages likes and subscriptions, and promotes free IBM CloudLabs browser‑based Kubernetes labs. ## Full Transcript
0:01When you make a pod in Kubernetes, what  happens behind the scenes? 0:05How do those Kubernetes components work together to bring that pod into fruition? 0:10My name is Whitney Lee, I'm on  the cloud team here at IBM. 0:14So, this is a cool exercise. 0:16It kind of goes over all the basics of Kubernetes, 0:20but with the perspective of a pod being made. 0:22So, at the basis of our system we have our nodes. 0:27The nodes are the worker machines  that that back up the Kubernetes cluster. 0:33So, in Kubernetes there are two types of  nodes: 0:36we have the control nodes 0:40- and in our case we're going to do just one control node  for simplicity's sake, 0:45but you in a production level cluster you'd want at least 3 control nodes 0:49- and then we have the compute nodes. 0:54So, in our exercise here, we'll do two  compute nodes, 0:58but you could have many many compute nodes in a Kubernetes cluster. 1:03So, let's talk about a use case where we want to make a pod. 1:08Let's say I'm the one making a pod. 1:10So, here's me - my smile, long hair, 1:16ha ha, my bangs ... okay. 1:18So, I’m going to make a pod in Kubernetes, 1:22and when I make that call with a kubectl command. 1:29That's going to go into the Kubernetes  cluster and hit the Kube-API server. 1:37So, the Kube-API server is the main  management component of a Kubernetes cluster. 1:46Now, the first thing that the Kube-API server  is going to do with my request to make a pod, 1:53is it is going to authenticate it and  validate it. 1:57So, it's going to say, “Who are you? Do you have  access to this cluster?” 2:02Like, “Oh, you're Whitney! Cool, we  know you. Come on in, make a pod!” 2:08So, the next thing that happens is the Kube  API server is going to write that pod to etcd. 2:17etcd is a key value data store  that's distributed across the cluster 2:22and it is the source of truth  for the Kubernetes cluster. 2:26(Word on the street is we have a  really good IBM Cloud video about it) 2:31So, Kube API server writes that request to etcd,  and then etcd will return when 2:40it has made a successful write, 2:42and then, at that point, the Kube-API server already is going to return to me that it's created 2:50- even though not a lot has happened in our system yet. 2:56That's because, at its core, Kubernetes 3:00and etcd has defined a desired state of what the system looks like, 3:04and then all the Kubernetes components  that we're going to talk about today 3:07work together to make that desired state equal  to the actual state. 3:11So, now that we have the pod recorded in the desired state, 3:14it is as good as created, as far as Kubernetes is concerned. 3:18The next component I want to  talk about is the scheduler. 3:26The scheduler is keeping an eye out for  workloads that need to be created, 3:35and what it's going to do is determine which  node it goes on. 3:38But what it's doing in the short term is, it's pinging our Kube-API server at regular intervals 3:48to get a status of whether there are any workloads that need to be scheduled. 3:52So, usually like five seconds. 3:53So, the Kube scheduler is ... the scheduler,  excuse me, it's going to ping the Kube API server, 3:59“Hey, do we have any workloads  that need to be created? No? OK.” 4:04“How about now? Are there any workloads now?  No? All right.” 4:10“How about now?” 4:11“Oh, Whitney has a pod that needs  to get created. Let's do that." 4:16So, now that the scheduler knows that pod needs  to get created on one of our compute nodes, 4:22let's take a pause from this and talk  about our compute nodes for a moment. 4:27Our compute nodes have three major  components: one is a Kubelet. 4:35The Kubelet is how the compute node  communicates with the control plane, 4:42or with specifically the Kube-API server. 4:46So, each each compute node has a Kubelet. 4:49So, the Kubelet is going to register the node with  the cluster. 4:54It will send periodic health check so that the Kube-API server knows that our compute nodes are healthy, 5:00and it will also create and destroy workloads as directed by the Kube-API server. 5:06Each of our compute nodes is also going to have 5:10a container runtime engine that's  compliant with container runtime initiative, 5:16and so, in the past, it's been Docker but it could  really be anything that's compliant - 5:23and then, finally, it has a Kube proxy which  isn't needed to create our pod today, 5:30but I would be remiss if I didn't mention it 5:34- and the Kube proxy is going to help the compute nodes communicate with one another 5:39if there are any workloads that span across more than one node. 5:43Just generally it helps them communicate. 5:48Okay, that said, now we have our scheduler. 5:53A scheduler is aware that we  need to schedule Whitney's pod. 5:58What our scheduler is going to do is look at the  available compute nodes. 6:02It's going to rule out any that are unsatisfactory either because of limitations 6:08that maybe the cluster administrator set up, 6:10or maybe it just doesn't have enough space for my pod, 6:13and then of the ones that are left it'll choose the best one to run the workload on, 6:17taking all the factors into account. 6:21Once it has made that choice,  does it schedule the workload? 6:24No, all it does is tell the Kube-API  server where it should go. 6:29Once the Kube-API server knows where it  should go, does it schedule the workload? 6:34No, what it does is it writes it to etcd, 6:37and then after the successful writes, then we have the desired state versus the actual states and  the Kube-API server knows what it needs to do 6:44to make that desired state ... the actual state  meet the desired state 6:49and what that is, is that's when the Kube-API server is going to let the Kubelet know let's say the scheduler said we 6:56should run the pod on node 2. 6:59So, that's when it's going to let the Kubelet know, “On node 2 we need to spin up a pod on this cluster.” 7:05The Kubelet is going to work together with the container runtime engine 7:09and make a pod that has the appropriate container running inside. 7:14So, we have made a pod on a Kubernetes cluster, 7:19but there's one more management  piece I want to talk about. 7:23Let's consider a case where, when I made the  pod, I set the restart policy to “always”, 7:30and then let's say my pod - something happens and it goes down. 7:35How will the system know that I want a new pod to be created in its place? 7:40That is where the controller manager comes in. 7:44This is the last important component of Kubernetes. 7:48So, the controller manager ... 7:53... it is made up of all of the controllers. 7:57So, there are many controllers that are controlled by the controller manager. 8:01And, in particular, the one that's going to help me make a new pod. 8:08For me. I'm not doing anything at  this point, my job is done up there, 8:12but the controller manager, it's the replication  controller within the controller manager 8:18that's going to help with this task. 8:20So, the controller manager - all the different  controllers are watching different pieces of the   Kubernetes system: 8:25the replication controller, just like the scheduler - 8:29these controllers are pinging the Kube-API server at a regular basis 8:33to get an update on the actual state of the cluster 8:37to make sure the desired state and the  actual states are the same as one another. 8:41So, the replication controller sees,  from contacting the Kube-API server, 8:47sees that my pod is gone, 8:49and it will take the necessary steps to spin that pod back up, 8:54- or create a new pod, honestly,  because pods are ephemeral. 9:01So, in conclusion, all these components  are working together just to make my pod - 9:09and especially we have the Kube-API server, the  main management component of the cluster, 9:14we have etcd, our data store and our source of truth for the cluster, 9:19the scheduler that helps determine which of the compute nodes the workload should go  on to, 9:23and the controller manager that is watching the desired state - the actual state - and making sure it's the same as the desired state. 9:31Thank you. If you have any questions  please drop us a line below. 9:36If you want to see more videos like this in  the future, 9:39please like and subscribe. 9:41And don't forget: you can grow your skills and earn a badge with IBM CloudLabs, 9:47which are free browser-based interactive Kubernetes labs.