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

# Demo PODS with YAML

> This guide explains how to create and deploy a Kubernetes Pod using a YAML manifest without `kubectl run`.

In this guide, you'll author a `pod.yaml` manifest and deploy a simple NGINX Pod without using `kubectl run`. Defining Pods in YAML is ideal for version control, reproducibility, and automation in CI/CD pipelines.

## 1. Create the YAML file

1. Open your terminal and launch your editor to create **pod.yaml**:
   ```bash theme={null}
   vim pod.yaml
   ```
2. Every Pod manifest requires four top-level fields:
   ```yaml theme={null}
   apiVersion: v1
   kind: Pod
   metadata:
   spec:
   ```

## 2. Add metadata

Under `metadata`, set a unique name and labels to organize and select resources:

```yaml theme={null}
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
    tier: frontend
spec:
```

<Callout icon="lightbulb" color="#1CB2FE">
  YAML is sensitive to spaces. Always use **two spaces** per indent level and avoid tabs.
</Callout>

## 3. Define the Pod spec

Inside `spec`, list your containers. Each entry needs at least `name` and `image`:

```yaml theme={null}
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
    tier: frontend
spec:
  containers:
    - name: nginx
      image: nginx
```

Add more containers by appending additional list items under `containers`.

Save and exit your editor (e.g., in Vim: `Esc` then `:wq`).

## 4. Verify the manifest

Inspect the content to ensure indentation and syntax are correct:

```bash theme={null}
cat pod.yaml
```

Expected output:

```yaml theme={null}
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
    tier: frontend
spec:
  containers:
    - name: nginx
      image: nginx
```

## 5. Deploy the Pod

Apply the YAML manifest to create the Pod:

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

You should see:

```console theme={null}
pod/nginx created
```

<Callout icon="triangle-alert" color="#FF6B6B">
  `kubectl apply -f` is idempotent and tracks changes, while `kubectl create -f` errors if the object already exists. For iterative edits, prefer `apply`.
</Callout>

Use this command to check the Pod's status:

```bash theme={null}
kubectl get pod nginx
```

Wait until `STATUS` transitions to **Running**.

## 6. Inspect and debug

For detailed Pod information and events:

```bash theme={null}
kubectl describe pod nginx
```

Sample output highlights Pod health, container state, and recent events:

```console theme={null}
Name:         nginx
Namespace:    default
Status:       Running
IP:           172.17.0.3
Containers:
  nginx:
    Image:     nginx
    State:     Running
    Ready:     True
    Restart Count: 0
Events:
  Type    Reason     Age   Message
  ----    ------     ----  -------
  Normal  Scheduled  10s   Successfully assigned default/nginx to minikube
  Normal  Pulling    10s   Pulling image "nginx"
```

## Quick Reference

| Command                   | Description                 | Example                      |
| ------------------------- | --------------------------- | ---------------------------- |
| Create or update resource | Apply YAML manifest         | `kubectl apply -f pod.yaml`  |
| List Pods                 | View Pod status             | `kubectl get pod nginx`      |
| Describe Pod              | Detailed Pod and event logs | `kubectl describe pod nginx` |

## Links and References

* [Kubernetes Official Documentation](https://kubernetes.io/docs/)
* [YAML Specification](https://yaml.org/spec/)
* [kubectl Cheat Sheet](https://kubernetes.io/docs/reference/kubectl/cheatsheet/)

***

Next, explore advanced manifest templating with Kustomize and Helm.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/docker-certified-associate-exam-course/module/d9358627-4fc7-4acc-ab96-fa25232555c6/lesson/8c84a314-515e-431e-9dbe-62c434da9772" />
</CardGroup>
