YAML
ActiveYAML Ain't Markup Language is a human-readable data serialization format designed for configuration files and data exchange. YAML 1.2.2 (2021) is a strict superset of JSON. It is the primary configuration language for Kubernetes, GitHub Actions, Docker Compose, Ansible, and most modern DevOps tooling.
In one line
YAML (YAML Ain't Markup Language) is defined by the yaml.org 1.2.2 spec (2021). It is a strict superset of JSON – every valid JSON document is valid YAML. YAML adds block style (indentation-based), comments, multi-line strings, anchors/aliases for deduplication, and type tags. It is the dominant format for Kubernetes manifests, GitHub Actions workflows, and Docker Compose files.
Quick Reference
| Field | Size | Description |
|---|---|---|
| Superset of JSON | Yes | Every valid JSON document is valid YAML 1.2. Parsers that target 1.1 may diverge on true/false vs yes/no. |
| Indentation | Spaces only | Block style uses 2-space indentation by convention. Tabs are forbidden as indentation characters. |
| Comments | # syntax | Comments begin with # and run to end of line. JSON has no comment syntax – this is YAML's most-used addition. |
| Scalars | 6 types | Strings, integers, floats, booleans (true/false only in 1.2), null, timestamps. Type inferred from value pattern. |
| Block sequences | - item | Arrays written as dash-prefixed items. Flow sequences use JSON array syntax [a, b, c]. |
| Block mappings | key: value | Maps written as key: value pairs. Flow mappings use JSON object syntax {a: 1, b: 2}. |
| Anchors/Aliases | &anchor *ref | & defines an anchor, * references it. Enables DRY configuration. Merge key << merges an anchored map. |
| Multi-line strings | | and > | Literal block scalar (|) preserves newlines. Folded block scalar (>) folds newlines to spaces. |
| Type tags | !!type | Explicit type: !!str "123" forces string. !!int, !!float, !!bool, !!null, !!timestamp available. |
Key Characteristics
Human-readable
Indentation-based structure is highly readable. Comments explain configuration intent. Dominant in DevOps tooling for this reason.
The Norway Problem
YAML 1.1 parsed country codes NO, FI, etc. as booleans. YAML 1.2 fixed this – true/false only. Legacy parsers (PyYAML < 6.0) still use 1.1 behavior.
Anchors and aliases
& and * enable DRY config. A single anchored map can be merged into many resources via <<: *anchor. Reduces repetition in large manifests.
Kubernetes native
All Kubernetes manifests are YAML. kubectl apply -f reads YAML. Helm charts are YAML templates. GitHub Actions workflows are YAML.
Message Format
# Kubernetes Deployment – block style YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
labels:
app: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
spec:
containers:
- name: my-app
image: my-app:1.0.0
ports:
- containerPort: 8080# Anchors and aliases – DRY configuration
x-defaults: &defaults
restartPolicy: Always
imagePullPolicy: IfNotPresent
containers:
- name: app
<<: *defaults # merge defaults
image: app:1.0
# Multi-line string styles
literal: |
Line one
Line two
Line three
folded: >
This long sentence
folds into one line.
# Explicit type tags
port: !!int "8080" # string "8080" coerced to int
token: !!str true # boolean true coerced to string