Creating Your First Pod Manifest: A Kubernetes YAML Guide
Master the art of writing your first Kubernetes Pod manifest. Learn to define essential image and port specifications in YAML to deploy your containers reliably.

Previously in this course, we explored The Pod: The Smallest Unit of Execution in Kubernetes. Now that you understand why Pods are the fundamental building block of your cluster, it is time to move beyond imperative kubectl run commands and define them using YAML.
Writing a Pod manifest is the bread and butter of daily operations in Kubernetes. A manifest is a YAML (YAML Ain't Markup Language) file that acts as a blueprint. It tells the Kubernetes API exactly what state you want your cluster to maintain.
The Anatomy of a Pod Specification
Every Kubernetes object requires four top-level fields in its specification. These fields tell the cluster who you are, what kind of object you're creating, and the details of the configuration.
apiVersion: Which version of the Kubernetes API to use (e.g.,v1).kind: The type of resource you are creating (in this case,Pod).metadata: Data that uniquely identifies the object, like itsnameorlabels.spec: The actual desired state, where we define containers, images, and ports.
Writing Your First Manifest
Let's create a manifest for a simple web server using the official Nginx image. Create a file named nginx-pod.yaml and add the following content:
YAMLapiVersion: v1 kind: Pod metadata: name: my-first-pod labels: app: web-server spec: containers: - name: nginx-container image: nginx:latest ports: - containerPort: 80
Breaking Down the Specification
containers: This is a list (indicated by the-dash). Kubernetes allows multiple containers in a single Pod, though usually, we keep it to one for simple apps.image: This points to the container registry.nginx:latesttells the Kubelet to pull the latest version of Nginx from Docker Hub.ports: This is documentation for the cluster. By definingcontainerPort: 80, you are explicitly stating that this container is listening on port 80. While not strictly required for the container to start, it is best practice for service discovery and documentation.
Hands-on Exercise: Define Your Own Pod
Now it's your turn to get hands-on.
- Create a new file called
hello-world.yaml. - Define a Pod named
hello-pod. - Use the
busyboximage. - Set the command to run
["echo", "Hello from Kubernetes!"]. (Hint: You will need to add acommand:field under the container spec). - Save the file. Don't worry about applying it yet—we will cover the application process in the next lesson.
Common Pitfalls
Even experienced engineers trip over these YAML nuances:
- Indentation Errors: YAML is strictly whitespace-dependent. Never use tabs; always use two spaces for each level of nesting.
- Case Sensitivity: Kubernetes fields are case-sensitive.
apiVersionis correct;apiversionwill result in a validation error. - The "List" Dash: Newcomers often forget the
-before the container name. If you omit that dash, Kubernetes interpretscontainersas a single object rather than a list, which will cause the manifest to fail validation. - Hardcoding Versions: Using
:latestin production is a dangerous practice because it makes deployments unpredictable. Always pin your images to a specific version (e.g.,nginx:1.25) to ensure your environment stays consistent across different runs.
Frequently Asked Questions
Does the order of fields in YAML matter?
Generally, no. As long as the indentation levels are correct, the order within a scope (like metadata or spec) does not affect the outcome.
Can I put multiple containers in one Pod? Yes, but they will share the same network namespace and storage. This is typically used for "sidecar" patterns, which we will cover later in the course.
How do I know what fields are available for a Pod?
You can use kubectl explain pod.spec in your terminal. This is a built-in documentation tool that saves you from searching the web for every configuration option.
Recap
We have moved from the concept of a Pod to the practical YAML definition required to create one. By defining the apiVersion, kind, metadata, and spec, you have created a declarative manifest that serves as the foundation for all your future deployments.
Up next: Applying Manifests to the Cluster, where we will take this YAML file and actually spin up the Pod in your local cluster.
Work with me

Next.js E-commerce Store Development
Turn your Facebook page or small shop into a real online store — fast, mobile-first, and built to sell. Own your storefront, not just a social page.

CI/CD Pipeline & Docker Containerization
Ship with confidence: automated CI/CD pipelines and Docker setups so every push is tested and deployed — no more manual, error-prone releases.


