Skip to main content
Hello and welcome to this lesson. In this lesson we’ll learn how to create a Pod using a YAML manifest and how to apply it to a cluster with kubectl.
A slide with a blue left pane reading "POD" and "With YAML." On the right is a blue open box icon with stacked documents coming out of it.
Kubernetes resources are typically defined with YAML manifest files. Each manifest follows a consistent structure: the four common top-level fields are apiVersion, kind, metadata, and spec. These are the root-level properties required by most Kubernetes objects. Details for each field:
  • apiVersion: Specifies which API version to use. Pods use v1 in the core API group. Other resources may use apps/v1, networking.k8s.io/v1, etc.
  • kind: The resource type you want to create (for example, Pod, Deployment, Service).
  • metadata: A map with identifying fields such as name, namespace, labels, and annotations.
  • spec: The specification for the resource. For Pods, spec must include a containers list where each container has at least a name and an image.
YAML is indentation-sensitive. Keys at the same logical level must have the same indentation. Under metadata, keys like name and labels should be siblings with the same indent; keys under labels must be further indented. Do not add arbitrary fields under metadata—only keys that Kubernetes expects (like name, namespace, labels, annotations, etc.).
For a Pod with a single container, spec.containers is a list. Each item in that list is a map describing a container (minimum: name and image). Below is a minimal, correct Pod manifest. Save it as pod-definition.yml.
Why this manifest works:
  • apiVersion: v1 and kind: Pod tell Kubernetes you’re creating a Pod using the core v1 API.
  • Under metadata, name is the Pod’s identifier and labels is a map used for selection and grouping.
  • spec.containers is a list allowing multiple containers in a single Pod; this example describes one container named nginx-container using the nginx image.
To create the Pod from this file, run:
You can also use kubectl apply -f pod-definition.yml to create or update a resource declaratively. To list Pods in the current namespace:
Example output:
To inspect the Pod in detail (labels, container images, events, start time, and troubleshooting info):
This prints a detailed description including assigned labels, container status, and recent events.
Pods are ephemeral. If a Pod is deleted or fails, it won’t be automatically recreated unless it is managed by a controller (for example, a Deployment or ReplicaSet). For production workloads, prefer using Deployments to manage Pod lifecycle and scaling.
Summary
  • Kubernetes manifests typically include apiVersion, kind, metadata, and spec.
  • Under metadata, use only supported fields such as name, namespace, labels, and annotations.
  • spec is resource-specific; for Pods it contains a containers list where each container has at least name and image.
  • Use kubectl create -f <file> or kubectl apply -f <file> to create resources, kubectl get pods to list Pods, and kubectl describe pod <name> for detailed information.
References A demo follows.

Watch Video