Kubernetes Pod Creation Process

>>> A comprehensive walkthrough of the Pod creation

Sai Manasa
3 min readOct 1, 2024
Flow: Pod Creation by Sai Manasa

Hello World… Creating a Pod in Kubernetes is a fundamental process that enables the deployment of containerized applications within a cluster. A Pod represents the smallest deployable unit in Kubernetes, encapsulating one or more containers that share the same network and storage. This guide provides a step-by-step breakdown of the Pod creation process, starting from writing the Pod definition file to its deployment and management within the cluster. Whether you’re a beginner or looking to refine your Kubernetes skills, this guide offers a clear and comprehensive overview. So, let’s get started…

Overview:

Creating a Pod in Kubernetes using a definition file involves a series of interactions between various components in the Kubernetes architecture.

Process:

  • Prepare the pod definition file, written in JSON or YAML format.
  • This file contains the specifications of the pod, including metadata like names, labels, container images, and other configuration details.
  • The below manifest defines a Pod my-nginx-pod, which runs a single container called nginx-container, using the nginx image.
  • The Pod creation process starts when you submit the pod definition file to the Kubernetes cluster using the below kubectl command:
kubectl create -f nginx-pod.yaml

kubectl apply -f nginx-pod.yaml
  • This command sends the contents of the file to the Kubernetes API Server.
  • The API server is the front-end interface for the Kubernetes control plane.
  • The API Server validates the request by checking if the submitted YAML file is well-formed and conforms to the Kubernetes schema (ex: correct API version, kind: Pod, and required fields).
  • If valid, the API Server writes the pod definition into etcd, the cluster’s distributed key-value store, where the cluster’s state is maintained.
  • Authentication and Authorization (above)
  • Once the pod specification is stored in etcd, the Kubernetes Scheduler continuously watches the API Server for unscheduled Pods.
  • When the scheduler detects the new Pod (i.e., a Pod without a node assigned), it starts the process of selecting an appropriate worker node for the Pod based on the available resources and scheduling policies (e.g., resource requests, node affinity, taints, and tolerations).
  • The Scheduler selects a node for the Pod and assigns it by updating the Pod object in the API server, indicating which worker node will host the Pod.
  • This update is again written to etcd, marking the Pod as scheduled.
  • Each worker node runs a kubelet, which is responsible for managing Pods on that node.
  • The kubelet on the selected worker node continuously polls the API Server to identify new Pods assigned to it. Upon detecting the newly scheduled Pod, it fetches the pod specification from the API Server.
  • The kubelet communicates with the container runtime (e.g., Docker, containerd, or CRI-O) on the worker node to pull the required container image(s) (e.g., nginx in this case) from the container registry.
  • If the image is not already present on the node, the container runtime pulls it from a container registry (like Docker Hub, Google Container Registry, etc.).
  • After pulling the image, the container runtime creates and starts the container(s) as defined in the Pod specification.
  • Once the container is running, the kubelet continues to monitor the Pod’s health by executing the specified liveness and readiness probes.
  • If the Pod fails (e.g., due to crashes or health issues), the kubelet may restart the container based on the Pod’s restart policy (e.g., Always, OnFailure, or Never).
  • As the Pod moves through different stages (e.g., Pending, Running, Succeeded, or Failed), the kubelet continuously updates the Pod’s status in the API Server.
  • The API server updates the pod’s status in etcd, and the user can query the API server to check the state of the newly created pod.

Sequence Diagram:

Let’s Connect:

Feel free to get in touch, share your ideas or feedback, or ask any questions you might have. I’m excited to engage with you and learn from each other as we navigate this exciting field!

LinkedIn: Sai Manasa

GitHub: Sai Manasa

Happy Learning 😄

--

--

No responses yet