> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pods with YAML

> How to write and apply a Kubernetes Pod YAML manifest, covering required fields, example Pod, indentation pitfalls, and kubectl commands to create and inspect Pods

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.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/nYh5ESbtPa0_kgi9/images/Crash-Course-Kubernetes-For-Absolute-Beginners/Kubernetes-Basics/Pods-with-YAML/yami-file-open-box-slide.jpg?fit=max&auto=format&n=nYh5ESbtPa0_kgi9&q=85&s=a22ba87b794c2412f69794f33dc7f3b1" alt="A minimalist slide showing a white open box icon and a file labeled &#x22;YAMI&#x22; floating above it on a dark blue curved background, with the rest of the slide left blank. A small &#x22;Copyright KodeKloud&#x22; appears in the bottom-left corner." width="1920" height="1080" data-path="images/Crash-Course-Kubernetes-For-Absolute-Beginners/Kubernetes-Basics/Pods-with-YAML/yami-file-open-box-slide.jpg" />
</Frame>

## 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`).

| Field | Purpose | Typical example |
| - | - | - |
| `apiVersion` | API group and version for the object | `v1`, `apps/v1` |
| `kind` | The resource type to create | `Pod`, `Deployment`, `Service` |
| `metadata` | Object identity and metadata such as `name`, `labels`, `namespace`, `annotations` | `name: myapp-pod` |
| `spec` | Desired state of the object; structure varies by `kind` | For Pods: a `containers` list with `name` and `image` |

Some resources may omit `spec` or include additional required fields. For core objects like Pods use `apiVersion: v1`; other resources often use `apps/v1`.

<Callout icon="lightbulb" color="#1CB2FE">
  Always use consistent spaces (not tabs) for indentation in YAML. Incorrect indentation can change structure or make the file invalid.
</Callout>

## Example: Single-container Pod manifest

This minimal Pod manifest creates a Pod named `myapp-pod` that runs an `nginx` container:

```yaml theme={null}
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
    type: front-end
spec:
  containers:
    - name: nginx-container
      image: nginx
```

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:

```yaml theme={null}
metadata:
  name: myapp-pod
    labels:
      app: myapp
```

Both `name` and `labels` must be siblings under `metadata` (same indentation level):

```yaml theme={null}
metadata:
  name: myapp-pod
  labels:
    app: myapp
```

## Create and inspect the Pod

Save the manifest to a file, for example `pod-definition.yaml`, and apply it with:

```bash theme={null}
kubectl create -f pod-definition.yaml
```

Useful inspection commands:

* List Pods:

```bash theme={null}
kubectl get pods
```

* View detailed Pod information:

```bash theme={null}
kubectl describe pod myapp-pod
```

* Get the Pod manifest as stored in the API server (YAML output):

```bash theme={null}
kubectl get pod myapp-pod -o yaml
```

## 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:

* [Kubernetes API concepts](https://kubernetes.io/docs/concepts/overview/working-with-objects/api-overview/)
* [kubectl documentation](https://kubernetes.io/docs/reference/kubectl/overview/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/crash-course-kubernetes-for-absolute-beginners/module/c648e3a3-f425-456e-af2d-4d5526626094/lesson/adcb6ed2-03a4-482e-a8fc-4d066e15c0b3" />

  <Card title="Practice Lab" icon="flask-conical" cta="Learn more" href="https://learn.kodekloud.com/user/courses/crash-course-kubernetes-for-absolute-beginners/module/c648e3a3-f425-456e-af2d-4d5526626094/lesson/7acc2004-0f08-45f4-b864-c6ec7450af2a" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.