The Complete YAML Course for DevOps

SurajSuraj
6 min read

What is YAML?

YAML is a human-friendly data serialization language that's used across all programming languages.

  • It’s not a programming language, it’s a data format.

  • It’s similar to JSON and XML.

  • You can only store data, not run commands.

YAML FULL FORM:

  • Previously: "Yet Another Markup Language"

  • Now: "YAML Ain't Markup Language"

But Why This Change?

Markup languages like HTML are designed to store documents. But YAML? It can do more than just that — it can store structured data, like objects. That’s why it’s called “YAML Ain’t Markup Language” now — to clarify that it’s not limited to markup.

Data Serialization:

  • Serialization is the process of converting a data object—a combination of code and data represented within a region of data storage—into a series of bytes that saves the state of the object in an easily transmittable form. In this serialized form, the data can be delivered to another data store (such as an in-memory computing platform), application, or some other destination.

  • In simple words, data serialization is the process of converting an object into a stream of bytes to save or transmit it more easily.

Data serialization is the process of converting an object into a stream of bytes to more easily save or transmit it.

  • The reverse of this process is called De-Serialization

Data Serialization languages:

  • YAML

  • JSON

  • XML

Where YAML Is Used?

  • Kubernetes config files (*.yaml)

  • Docker Compose

  • GitHub Actions workflows

  • CI/CD pipelines

  • Logs, caching systems, etc.

Benefits of YAML:

  • Simple & easy to read

  • Clean syntax (but indentation matters!)

  • Converts easily to JSON, XML

  • Language-agnostic (used in most stacks)

  • Can represent complex data structures

  • Parsing YAML is easy using various tools/parsers

Creating a YAML File

YAML uses key-value pairs and lists. Think of it like dictionaries in Python or HashMaps in Java.

Also:

  • YAML is case-sensitive

  • Indentation is mandatory

Strings and Multiline Texts

myself: Suraj kumar
fruit: "Apple"
job: 'DevOps'

bio: |
  Hey there my name is Suraj and currently learning YAML
  I am a very enthusiastic about learning new things.

message: >
  this will
  all be 
  in one single line

# Same as:
message: !!str this will all be in one single line

| → preserves newlines
> → converts into a single line (removes newlines)

Numbers and Booleans

In YAML, you can represent all types of numbers — integers, floats, binary, hex, exponential — and even booleans with chill syntax.

number: 6549864          # Integer
marks: 45.12             # Float

booleanValue: !!bool No  # Boolean → false
# Valid false: no, n, false, False
# Valid true: yes, y, true, True

zero: !!int 0
positiveNum: !!int 55
negativeNum: !!int -55
binaryNum: !!int 0b11001     # Binary
octalNum: !!int 0123         # Octal
hexa: !!int 0x45             # Hexadecimal
commaValue: !!int +540_000  # 540000 (underscores allowed)

exponential_numbers: 5.125E56 # Exponential float

marks: !!float 57.98
infinite: !!float .inf        # Infinity
not_a_num: .nan               # Not a number

🧠 YAML even understands underscores in large numbers and scientific notation!

Null Values

YAML supports nulls (empty/missing values) using null, Null, ~, or just leaving it blank.

surname: !!null Null  # null key with null value
~: This is a null key  # Null key with a value

🔥 You can use nulls to mark something intentionally empty.

Dates and Time

Dates and timestamps are built-in. You can write simple dates or full timestamps (with or without timezone).

date: !!timestamp 2024-2-4
India time: 2024-2-4T02:59:43.10 +5:30
no_time_zone: 2024-2-4T02:59:43.10

✅ YAML can auto-parse this as date/time objects in most languages.

Sequence Datatype (Lists)

Lists in YAML are written with dashes - or inline with square brackets [].

student: !!seq
 - marks
 - name 
 - roll_no

# Same as:
student: [marks, name, roll_no]

# Sparse list → Some values can be left empty
sparse_seq: 
 - hey
 - how 
 - 
 - Null
 - sup

🚀 Great for defining arrays or ordered values.

Nested Sequences

YAML also supports nested lists (lists inside lists):

- 
 - mango 
 - apple
 - banana
-
 - marks
 - roll_no
 - date

It’s like having arrays inside arrays 📦

Mapping (Key:Value) or Dictionary

Basic dictionary in YAML is just key: value. You can also nest them or use inline format.

name: Suraj kumar
role: 
   age: 21
   job: student

# Inline version:
role: {age: 21, job: student}

💡 Use this for configs, JSON-style data, etc.

!!pairs (Duplicate keys allowed)

When you wanna allow duplicate keys, use !!pairs.

pair_example: !!pairs
 - job: student
 - job: teacher

# Same as:
pair_example: !!pairs [job: student, job: teacher]

🧩 This is useful for APIs that accept repeated fields.

!!set (Unique values only)

If you want a set of unique keys, use !!set:

names: !!set
 ? suraj
 ? mohit
 ? mahesh

Each key in a set is unique and holds a null/empty value by default.

!!omap (Ordered dictionary)

When the order of key-value pairs matters, go for !!omap:

people: !!omap
 - Suraj:
     name: Suraj kumar
     age: 21
     height: 678
 - Mohit:
     name: Mohit joping
     age: 22
     height: 768

🎯 Super helpful when ordering is important (like user rankings, configs, etc.)

Reusing Properties with Anchors (& and *)

You can reuse data using anchors (&) and aliases (*):

liking: &likes
  fav_fruit: apple
  dislikes: grapes

person1:
  name: Suraj kumar
  <<: *likes

person2:
  name: Mohit joping
  <<: *likes
  dislikes: berries

So basically:

  • &likes defines a reusable block.

  • *likes pulls that block wherever you want.

  • <<: *likes merges it into another object.

🙌 This avoids repetition in large configs.

Storing Data in XML (Extensible Markup Language)

XML is a markup language used to store and transport data. It looks like HTML but is designed for data, not UI.

<?XML version="1.0" encoding="UTF-8"?>
<College name="GITM" principal="Someone">
    <Students>
        <Student>
            <rollno>9</rollno>
            <name>"Suraj"</name>
            <marks>80</marks>
        </Student>       
    </Students>
</College>

Explanation:

  • <?XML ... ?> → This is the declaration. It tells the parser this is an XML doc.

  • <College> is the root element. It has attributes like name and principal.

  • Inside, we nest <Students>, and inside that, a <Student> with info.

  • XML is strict with opening/closing tags and proper nesting.

✅ Used in many legacy systems, APIs, config files, and document storage.

Storing Data in JSON (JavaScript Object Notation)

JSON is the go-to format for modern APIs and apps — lightweight, easy to read/write, and works across all programming languages.

{  
   "College": [ 
       {
          "name": "GITM",
          "principle": "Someone",
          "Students": [
                 {
                    "rollno": 2,
                    "name": "Suraj kuamr",
                    "marks": 78
                  }
            ]
        }
     ]
}

Explanation:

  • JSON uses {} for objects (like dictionaries) and [] for arrays (lists).

  • Everything is in key: value pairs.

  • Strings must be in double quotes (" ").

  • Commas are required between fields (unlike YAML).

🔥 JSON is everywhere — web apps, APIs, config files, databases, you name it.

YAML DevOps tools

Blog:How to validate Kubernetes YAML files

Here are some tools used to validate and manage YAML configs in the DevOps world:

1. Datree

Used to validate Kubernetes YAML files and catch misconfigurations.

2. Monokle Desktop IDE

A dedicated IDE for managing Kubernetes YAMLs with preview and validation.

3. Lens IDE

Kubernetes IDE to manage clusters and YAML configs visually.

This YAML learning I documented from kunal kushwaha's DevOps course. This is easy isn't it. So this is for today I'll be come with the next blog of DevOps practices soon.

1
Subscribe to my newsletter

Read articles from Suraj directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Suraj
Suraj

I'm a Developer from India with a passion for DevOps ♾️ and open-source 🧑🏻‍💻. I'm always striving for the best code quality and seamless workflows. Currently, I'm exploring AI/ML and blockchain technologies. Alongside coding, I write Technical blogs at Hashnode, Dev.to & Medium 📝. In my free time, I love traveling, reading books