0
0
Kubernetesdevops~10 mins

Pod definition in YAML in Kubernetes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Pod definition in YAML
Start YAML file
Define apiVersion
Define kind: Pod
Define metadata: name, labels
Define spec: containers list
Define each container: name, image, ports
End YAML file
This flow shows how a Pod YAML is structured step-by-step from top-level fields to container details.
Execution Sample
Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: my-container
    image: nginx
    ports:
    - containerPort: 80
This YAML defines a Pod named 'my-pod' with one container running nginx on port 80.
Process Table
StepYAML SectionActionValue SetNotes
1apiVersionSet API versionv1Specifies Kubernetes API version
2kindSet resource typePodDefines this resource as a Pod
3metadataSet metadata blockname: my-podNames the Pod 'my-pod'
4specSet spec blockcontainers: listDefines containers in the Pod
5containers[0]Define containername: my-containerFirst container named 'my-container'
6containers[0]Set imagenginxContainer runs nginx image
7containers[0]Set portscontainerPort: 80Container exposes port 80
8EndYAML completePod definition readyPod YAML is valid and ready for use
💡 All required fields set; YAML defines a valid Pod with one container.
Status Tracker
FieldStartAfter Step 3After Step 7Final
apiVersionundefinedv1v1v1
kindundefinedPodPodPod
metadata.nameundefinedmy-podmy-podmy-pod
spec.containersundefinedundefined[{name: my-container, image: nginx, ports: [{containerPort: 80}]}][{name: my-container, image: nginx, ports: [{containerPort: 80}]}]
Key Moments - 3 Insights
Why do we need to specify 'apiVersion' and 'kind' at the top?
These fields tell Kubernetes what type of resource you are creating and which API version to use, as shown in steps 1 and 2 of the execution table.
What happens if we forget to define 'containers' under 'spec'?
The Pod would be invalid because Kubernetes requires at least one container in the Pod spec, as seen in step 4 where containers list is defined.
Why do we indent 'name', 'image', and 'ports' under the container?
Indentation shows these fields belong to the container object inside the containers list, demonstrated in steps 5 to 7.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of 'kind' after step 2?
APod
Bv1
Cmy-pod
Dcontainers
💡 Hint
Check the 'Value Set' column at step 2 in the execution table.
At which step is the container image set to 'nginx'?
AStep 3
BStep 5
CStep 6
DStep 7
💡 Hint
Look for 'Set image' action in the execution table.
If we remove the 'ports' section, which step would be missing?
AStep 4
BStep 7
CStep 6
DStep 8
💡 Hint
Ports are set in step 7 according to the execution table.
Concept Snapshot
Pod YAML structure:
apiVersion: v1
kind: Pod
metadata:
  name: pod-name
spec:
  containers:
  - name: container-name
    image: image-name
    ports:
    - containerPort: port-number

Indentation shows hierarchy; containers list is required.
Full Transcript
This visual execution traces a Kubernetes Pod definition in YAML. It starts with setting the apiVersion and kind fields to specify the resource type. Then metadata is defined to name the Pod. The spec section contains a list of containers. Each container has a name, image, and optionally ports. The execution table shows each step setting these fields. The variable tracker shows how fields get their values step-by-step. Key moments clarify why apiVersion and kind are needed, why containers are required, and the importance of indentation. The quiz tests understanding of these steps. The snapshot summarizes the YAML structure and key rules for defining a Pod.