As I continue learning DevOps, I’ve started noticing one thing everywhere: YAML.

Whether it’s Kubernetes, Docker Compose, Prometheus, or other DevOps tools, YAML appears again and again in configuration files. I used to look at these files and think, “It’s just configuration.” But after spending some time understanding YAML itself, I realized that knowing the syntax makes many of these tools much easier to understand.
So, here’s what I learned about YAML and the concepts that stood out to me.
What exactly is YAML?
YAML is a human-readable data serialization language. Like JSON and XML, it provides a common format that applications can use to represent and exchange structured data.
What makes YAML especially popular in DevOps is its readability.
Compare the same kind of structured information in different formats, and YAML often looks much cleaner because it relies heavily on indentation and spacing rather than lots of brackets and special characters.
That’s one of the reasons YAML works so well for configuration files.
The most important thing I learned: indentation matters!
This was probably the biggest takeaway for me.
In YAML, indentation isn’t just for making the file look pretty — it defines the structure of the data.
For example:
microservice:
name: shopping-cart
port: 9000
version: 1.7
Here, name, port, and version belong to microservice.
The indentation tells YAML about that relationship.
That’s different from formats like JSON, where curly braces explicitly define the structure.
So when working with YAML, inconsistent indentation can actually make the file invalid.
A good way to think about YAML is:
Indentation = structure.
YAML starts with simple key-value pairs
The most basic YAML structure is a key-value pair:
name: nginx
port: 9000
version: 1.7
It’s very straightforward:
key: value
YAML can represent different types of values, such as strings and numbers.
Strings can often be written without quotes:
name: nginx
but you can also use quotes:
name: "nginx"
or:
name: 'nginx'
Comments make YAML easier to understand
Comments start with #.
# Application configuration
name: nginx
port: 9000
Comments don’t affect the configuration itself, but they can make configuration files much easier for other people to understand.
This becomes especially useful when YAML files get large.
Objects and nesting
We can group related key-value pairs together using indentation.
For example:
microservice:
name: shopping-cart
port: 9000
version: 1.7
You can visualize this as:
microservice
├── name
├── port
└── version
Once I understood this concept, Kubernetes YAML started making much more sense.
For example:
metadata:
name: nginx-pod
labels:
app: nginx
Here we have an object inside another object:
metadata
├── name
└── labels
└── app
It’s really just nesting.
Lists in YAML
Another important concept is the list.
YAML uses - to represent list items.
services:
- frontend
- backend
- database
We can also have a list of objects:
services:
- name: frontend
port: 9000
version: 1.7
- name: backend
port: 9001
version: 2.0
Now each - represents an object.
This is particularly important in Kubernetes because many Kubernetes fields are lists of objects.
Lists can also use square brackets
For simple lists, YAML also supports a shorter syntax:
versions: [2.0, 2.1, 2.2]
Instead of:
versions:
- 2.0
- 2.1
- 2.2
Both represent a list.
For short lists, the square-bracket version can be convenient. For more complex structures, the multiline version is usually easier to read.
Lists inside objects inside lists
This is where things started becoming really interesting for me.
Consider a simplified Kubernetes-style example:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
Let’s break it down:
containers
↓
list
↓
object
├── name
├── image
└── ports
↓
list
↓
object
Once you learn to see YAML this way, large Kubernetes manifests become much less intimidating.
Instead of seeing a huge block of configuration, you can break it down into:
key → object → list → object → nested list
YAML and Kubernetes
This was probably the most useful connection for me.
A Kubernetes manifest might look complicated at first:
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
But when you understand YAML, the structure becomes easier to read.
You can identify:
- Key-value pairs
- Nested objects
- Lists
- Objects inside lists
- Lists inside objects
The tutorial uses a Kubernetes Pod example to demonstrate exactly these building blocks.
That made me realize that learning YAML isn’t just about learning another configuration format.
It’s also about learning how to read Kubernetes manifests.
Multiline strings
Another useful YAML feature I learned about is the | symbol.
It can be used when we want to represent a multiline string.
For example:
script: |
echo "Hello"
echo "World"
echo "Done"
The line breaks are preserved.
This becomes particularly useful in Kubernetes when we need to include a shell script or another configuration file inside a YAML manifest.
For example:
command:
- /bin/sh
- -c
- |
echo "Starting application..."
echo "Running setup..."
echo "Finished."
Instead of putting an entire script on one long line, we can keep it readable.
What about >?
YAML also has another useful multiline-string operator: >.
The basic difference I learned is:
| → preserve line breaks
> → fold lines into a single logical line
So:
message: |
hello
world
preserves the newline, while:
message: >
hello
world
treats the lines as a folded string.
YAML isn’t the same thing as templating
The YAML files also introduced placeholders such as:
{{ something }}
These are commonly seen when working with tools that generate configuration files.
One important distinction I took away is that this isn’t really YAML syntax itself.
It’s often a templating feature provided by another tool.
For example, tools such as Helm can process templates and generate the final YAML configuration.
So it’s useful to distinguish:
YAML
↓
data/configuration format
Templating
↓
generates or modifies that configuration
That distinction becomes important when moving deeper into Kubernetes and DevOps.
Multiple YAML documents in one file
I also learned that one YAML file can contain multiple documents.
They can be separated using:
---
For example:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
---
apiVersion: v1
kind: Service
metadata:
name: app-service
The --- separates the two YAML documents.
This is something you’ll often encounter when working with Kubernetes manifests.
A small warning about YAML
One thing I learned while going through this material is that YAML can look extremely simple, but there are some details that can become tricky.
For example, YAML parsers can interpret values differently depending on their type rules, and features such as environment-variable expansion or template placeholders may actually be handled by the tool consuming the YAML rather than YAML itself.
So I don’t want to think of YAML as:
“Just a file with spaces.”
It’s better to think of it as:
A structured data format where whitespace and syntax determine how the data is interpreted.
My YAML cheat sheet
After learning the basics, this is the mental cheat sheet I’m keeping:
# Comment
name: nginx # Key-value pair
metadata: # Object
name: nginx
services: # List
- frontend
- backend
containers: # List of objects
- name: nginx
image: nginx
ports: [80, 443] # Short list
script: | # Multiline string
echo "Hello"
echo "World"
---
# Another YAML document
The five things I want to remember most are:
- Key-value pair
- Indentation / nesting
- Lists using
- - Lists of objects
- Multiline strings using
|
And then:
--- → separates YAML documents
Final takeaway
Before learning YAML, I mostly saw Kubernetes configuration as a wall of text.
Now I’m starting to see the structure underneath it.
YAML
│
├── Key-value pairs
│
├── Objects
│ └── Nested objects
│
├── Lists
│ └── Lists of objects
│
├── Multiline strings
│
└── Multiple documents
And that’s probably the biggest lesson for me:
You don’t need to memorize every YAML file. You need to understand the structure.
Once you understand how indentation, objects, lists, and nested structures work, reading Kubernetes YAML becomes much easier.
This is just one step in my DevOps learning journey, but I can already see why YAML is such an important skill for anyone working with Kubernetes and modern infrastructure.
What was the first YAML file that confused you when you started learning DevOps? 😄
#DevOps #YAML #Kubernetes #Docker #CloudNative