YAML Fundamentals
Pipelines, Docker Compose and Kubernetes are all configured in YAML. Small indentation mistakes break everything, so learn it properly.
On this page · 5 min · Intermediate
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Intermediate
- Updated
- Oct 29, 2026
Related tutorials
Learning objectives#
- Write maps, lists and nested structures
- Use multi-line strings
- Avoid indentation and type pitfalls
- Validate YAML
Explanation#
YAML uses key: value pairs. Indentation (spaces only, never tabs) shows nesting.
Lists use a dash per item, or inline [a, b].
Multi-line strings: | keeps line breaks (scripts), > folds them into spaces.
Watch types: yes/no and on/off can be read as booleans by some parsers; quote version numbers like "3.10" so they are not treated as numbers.
Code example: One file, all the basics#
app:
name: shop-api
replicas: 3
version: "1.10" # quoted: stays a string, not 1.1
features:
- search
- payments
env: { ASPNETCORE_ENVIRONMENT: Production, LOG_LEVEL: Information }
startup_script: |
dotnet ef database update
dotnet Shop.Api.dll
description: >
This long text is folded
into a single line.
{ "app": { "name": "shop-api", "replicas": 3, "version": "1.10",
"features": ["search", "payments"],
"env": { "ASPNETCORE_ENVIRONMENT": "Production", "LOG_LEVEL": "Information" },
"startup_script": "dotnet ef database update\ndotnet Shop.Api.dll\n",
"description": "This long text is folded into a single line.\n" } }This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- Two-space indentation nests keys under app.
- Dashes create a list.
- Inline braces create a map on one line.
- | keeps lines; > folds them.
Real-world use case#
Every GitHub Actions workflow, docker-compose.yml and Kubernetes manifest in this track.
Common mistakes#
YAML forbids tabs. Configure your editor to insert spaces.
Quote versions ("3.10"), times ("12:30") and values like "no" or "on".
Best practices#
- Two spaces per level
- Quote ambiguous values
- Validate with yamllint or your editor
- Keep files short; split when large
Remember this#
key: value, spaces only.
- item = list entry.
| keeps newlines, > folds them.
Practice exercise#
Your task: Write a YAML list of three regions: centralindia, southindia, westeurope.
Show solution
regions:
- centralindia
- southindia
- westeurope
Mini quiz#
Which character must never be used for YAML indentation?
Want more? Practise all DevOps MCQs · DevOps interview questions
My notes#
Saved in this browser.