⌂ Home

Syntax, indentation, and building blocks

Start here if manifests look like a wall of colons. This part covers the YAML rules that apply to every Pod, Service, and Deployment in the labs—before we talk about Kubernetes fields.

Goal: Read any lab YAML and recognize scalars, mappings, lists, and nesting. Avoid tabs, fix indentation errors quickly, and understand how a minimal Pod maps to YAML structure. Parts 2 and 3 cover Kubernetes object anatomy, editing workflows, editors, and troubleshooting.

Why Kubernetes uses YAML

Kubernetes stores desired state as API objects. You declare that state in files—almost always YAML—then run kubectl apply -f your-file.yaml. The control plane reconciles the cluster to match your spec.

YAML is indentation-based. Unlike JSON, there are no { } braces; spaces show what belongs to which parent key. That is why a single wrong indent breaks the whole file.

Rules to memorize

RuleWhat to do
No tabsUse the space bar (or editor “convert indentation to spaces”). Tabs cause parser errors.
Consistent depthUse 2 spaces per level—this matches most Kubernetes documentation.
Lists use -Each list item starts with - at the correct indent, then properties of that item are indented further.
Case-sensitivekind: Pod is valid; kind: pod is not.

Scalars (single values)

Strings, numbers, booleans—one value per key.

name: nginx
replicas: 3
enabled: true

Quote strings when they look like numbers or you need special characters: version: "1.20".

Mappings (nested objects)

A key whose value is another set of keys is a mapping. Child keys are indented deeper than the parent.

metadata:
  name: my-pod
  labels:
    app: demo

Lists (sequences)

Critical for containers and ports

Items in a list share the same parent key. Each item begins with -.

containers:
  - name: web
    image: nginx:1.25
  - name: sidecar
    image: busybox:1.36
The - for web and sidecar must align: both are direct children of containers:. Properties like name: and image: are indented one level deeper than -.

Minimal Pod (lab-shaped)

This mirrors the idea of k8s/labs/basics/apache1.yaml: one Pod, one container, one port.

apiVersion: v1
kind: Pod
metadata:
  name: apache1
  labels:
    mycka: k8slearning
spec:
  containers:
    - name: mycontainer
      image: docker.io/httpd
      ports:
        - containerPort: 80

apiVersion + kind

Identifies which API endpoint handles the object (v1 for core Pod, apps/v1 for Deployment, etc.).

metadata vs spec

metadata is identity (name, labels). spec is what you want running—containers, volumes, and so on.

Comments and multiline text

Comments

# whole line comment
image: nginx:1.25  # inline

Multiline blocks

| keeps line breaks (common in ConfigMaps). > folds lines into a paragraph.

script.sh: |
  #!/bin/sh
  echo hello

Multiple objects in one file

Uses ---

Separate documents with --- on its own line. kubectl apply -f applies each object in order.

apiVersion: v1
kind: Namespace
metadata:
  name: demo
---
apiVersion: v1
kind: Pod
metadata:
  name: app
  namespace: demo
spec:
  containers:
    - name: app
      image: nginx:1.25

Next: Kubernetes fields and lab workflows

Continue to Part 2 — Objects, labels, Deployments, Services, and kubectl edit/apply patterns.