Course contentsShow
← Cloud and Infrastructure
Lesson 1147 of 2,98923. Kubernetes WorkloadsFree lesson

Creating Pods with YAML Manifests

Writing and applying basic Pod specifications using YAML configuration files.

Creating Pods with YAML Manifests

You'll learn how to write and apply a YAML file that tells Kubernetes exactly how to create a Pod.

What is a YAML Manifest?

In previous lessons, you've used kubectl commands like kubectl create to spin up Pods quickly. But for production environments, you'll write YAML manifests—declarative configuration files that describe exactly what you want Kubernetes to create. Think of it as a blueprint: instead of verbally instructing a builder, you hand them detailed architectural plans.

Basic Pod YAML Structure

Every Pod manifest follows a predictable pattern:

apiVersion: v1
kind: Pod
metadata:
  name: my-nginx-pod
  labels:
    app: nginx
spec:
  containers:
  - name: nginx-container
    image: nginx:1.21
    ports:
    - containerPort: 80

Breaking it down:

  • apiVersion: Tells Kubernetes which API version you're using (Pods use v1)
  • kind: Specifies you're creating a Pod
  • metadata: Includes the Pod name and labels for organization
  • spec: Defines the actual container(s), their images, and configuration

Applying Your Manifest

Save your YAML file (e.g., pod.yaml) and create the Pod:

kubectl apply -f pod.yaml

Kubernetes reads your manifest, validates it, and creates the Pod exactly as specified. You can verify with kubectl get pods or kubectl describe pod my-nginx-pod.

Key Takeaway: YAML manifests are the declarative, version-controlled way to define Pods—they capture your infrastructure as code, making deployments repeatable and auditable.