Skip to main content
In this lesson you’ll learn how to define and create a Kubernetes Pod using a YAML manifest. Kubernetes manifests are declarative configuration files that describe the desired state of cluster objects (like Pods). This page covers the required top-level fields, a practical Pod example, common YAML pitfalls, and the kubectl commands you use to apply and inspect the Pod.
A minimalist slide showing a white open box icon and a file labeled "YAMI" floating above it on a dark blue curved background, with the rest of the slide left blank. A small "Copyright KodeKloud" appears in the bottom-left corner.

Kubernetes manifest basics

Kubernetes objects are typically defined using YAML files. Most manifests include four top-level fields: apiVersion, kind, metadata, and spec. The exact structure of spec depends on the resource kind (for example, a Pod’s spec looks different from a Deployment’s spec). Some resources may omit spec or include additional required fields. For core objects like Pods use apiVersion: v1; other resources often use apps/v1.
Always use consistent spaces (not tabs) for indentation in YAML. Incorrect indentation can change structure or make the file invalid.

Example: Single-container Pod manifest

This minimal Pod manifest creates a Pod named myapp-pod that runs an nginx container:
Key points:
  • metadata.name is the unique name for the Pod (myapp-pod).
  • metadata.labels is a key/value map used for grouping and selecting objects later (for example with kubectl get pods -l app=myapp).
  • spec.containers is a list because a Pod can include multiple containers. Each container item must include at least name and image.

Common YAML indentation mistake

Incorrect indentation can change the document structure. In the example below labels is incorrectly indented under name, which is invalid:
Both name and labels must be siblings under metadata (same indentation level):

Create and inspect the Pod

Save the manifest to a file, for example pod-definition.yaml, and apply it with:
Useful inspection commands:
  • List Pods:
  • View detailed Pod information:
  • Get the Pod manifest as stored in the API server (YAML output):

Summary

  • Kubernetes manifests are YAML files that commonly include the four top-level fields: apiVersion, kind, metadata, and spec.
  • For a Pod, spec must include a containers array with at least name and image for each container.
  • YAML is indentation-sensitive — use consistent spacing and verify sibling relationships (e.g., name and labels under metadata).
  • Use kubectl create -f to create the Pod and kubectl get / kubectl describe / kubectl get -o yaml to inspect it.
Links and references:

Watch Video

Practice Lab