0
0
Kubernetesdevops~10 mins

Creating Pods with kubectl in Kubernetes - Visual Walkthrough

Choose your learning style9 modes available
Process Flow - Creating Pods with kubectl
Write Pod YAML file
Run kubectl apply -f pod.yaml
kubectl sends request to API Server
API Server validates and stores Pod spec
Scheduler assigns Pod to a Node
Kubelet on Node creates container
Pod status changes to Running
kubectl get pods shows Pod status
This flow shows how writing a Pod definition, applying it with kubectl, and Kubernetes components work together to create and run a Pod.
Execution Sample
Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: my-container
    image: nginx
This YAML defines a Pod named 'my-pod' running an nginx container.
Process Table
StepActionCommand/OperationResult/Output
1Write Pod YAML fileCreate pod.yaml with Pod specFile pod.yaml created with Pod definition
2Apply Pod YAMLkubectl apply -f pod.yamlPod 'my-pod' created in Kubernetes cluster
3API Server receives requestAPI Server validates Pod specPod object stored in etcd
4Scheduler assigns PodScheduler selects a NodePod assigned to Node 'node-1'
5Kubelet creates containerKubelet pulls nginx image and starts containerContainer running on Node
6Pod status updatePod status changes to Runningkubectl get pods shows STATUS=Running
7Verify Podkubectl get podsNAME READY STATUS RESTARTS AGE my-pod 1/1 Running 0 1m
💡 Pod is running successfully; kubectl get pods confirms the Pod status as Running.
Status Tracker
VariableStartAfter Step 2After Step 4After Step 6Final
Pod ObjectNot createdCreated in clusterAssigned to Node 'node-1'Container runningPod Running
Pod StatusNonePendingPendingRunningRunning
Key Moments - 3 Insights
Why does the Pod status show 'Pending' before it becomes 'Running'?
After applying the Pod YAML (Step 2), the Pod object exists but the scheduler has not assigned it to a Node yet (Step 4). During this time, the status is 'Pending' as Kubernetes prepares to run it.
What does 'kubectl apply -f pod.yaml' actually do?
It sends the Pod definition to the Kubernetes API Server which validates and stores it (Step 3). This command does not create the container directly but triggers the cluster to create the Pod.
How do we know the Pod is successfully running?
The final 'kubectl get pods' command (Step 7) shows the Pod with STATUS=Running and READY=1/1, meaning the container inside the Pod is up and running.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does the Pod get assigned to a Node?
AStep 3
BStep 4
CStep 5
DStep 6
💡 Hint
Check the 'Action' column for 'Scheduler assigns Pod' in the execution table.
According to the variable tracker, what is the Pod status after Step 2?
ASucceeded
BRunning
CPending
DFailed
💡 Hint
Look at the 'Pod Status' row under 'After Step 2' in the variable tracker.
If the container image was incorrect, which step would most likely fail?
AStep 5 - Kubelet creates container
BStep 3 - API Server validation
CStep 2 - Apply Pod YAML
DStep 7 - kubectl get pods
💡 Hint
Refer to the 'Kubelet creates container' action in Step 5 where the image is pulled and container started.
Concept Snapshot
Creating Pods with kubectl:
- Write Pod YAML file defining apiVersion, kind, metadata, spec
- Run 'kubectl apply -f pod.yaml' to send Pod spec to cluster
- API Server validates and stores Pod object
- Scheduler assigns Pod to a Node
- Kubelet on Node pulls image and starts container
- Pod status changes from Pending to Running
- Use 'kubectl get pods' to check Pod status
Full Transcript
To create a Pod in Kubernetes, you first write a YAML file describing the Pod's details like its name and container image. Then you run 'kubectl apply -f pod.yaml' which sends this definition to the Kubernetes API Server. The API Server checks the Pod spec and stores it. Next, the Scheduler picks a Node to run the Pod. The Kubelet on that Node pulls the container image and starts the container. The Pod status changes from Pending to Running once the container is up. You can verify the Pod is running by using 'kubectl get pods' which shows the Pod's status and readiness.