Back to programming
programming#yaml#config

YAML Explained with Examples

YAML is everywhere in DevOps (Docker Compose, Kubernetes, GitHub Actions). Learn its 6 rules and you're done.

Jane Contributor August 2, 2026 1 views

YAML in 10 Minutes

YAML is a human-friendly data format — like JSON but with less punctuation.

The 6 rules

  1. Indentation matters — 2 spaces per level. Never use tabs.
  2. key: value is a mapping.
  3. - item is a list item.
  4. Strings usually don't need quotes.
  5. # starts a comment.
  6. --- separates multiple documents in one file.

A working example (Kubernetes-ish)

apiVersion: v1
kind: Pod
metadata:
  name: web
  labels:
    app: nginx
    tier: frontend
spec:
  containers:
    - name: nginx
      image: nginx:1.27
      ports:
        - containerPort: 80
      env:
        - name: LOG_LEVEL
          value: info

Tricky parts

  • Strings that look like booleans or numbers can bite you:
    version: 3.10     # this is 3.1 (a float!)  Use "3.10" as string.
    release: yes      # this is boolean true (weird YAML 1.1)  Use "yes".
    
  • Anchors (advanced) let you reuse blocks:
    defaults: &defaults
      timeout: 30
      retries: 3
    api:
      <<: *defaults
      endpoint: /api
    

Real-world example

Docker Compose, GitHub Actions, Ansible, Kubernetes, Helm — you'll write YAML every single day. Install a YAML linter in your editor and you'll never miss an indent.

Keep reading

You may also like

Discussion (0)

No comments yet. Be the first to weigh in.

Leave a comment

Comments are reviewed before appearing.