Mastering YAML: How the Programming Language Can Benefit IT Pros

This guide looks how and why IT pros should use the YAML data serialization language.

Christopher Tozzi, Technology analyst

March 11, 2024

4 Min Read
YAML inscription against a laptop and code background
Alamy

Forget XML and HTML (or, at least, put them aside for now). There's another markup language that IT pros should know: YAML.

Well, actually, YAML isn't a markup language per se. But it comes close. And it's increasingly central to many of the core tasks that IT teams perform — such as application configuration, deployment, and management.

Keep reading for a primer on what IT engineers should know about YAML, as well as how to get started working with YAML code.

What Is YAML?

YAML is a language designed mainly to define software configurations in a way that is easy for humans to read.

In most respects, YAML (which is typically pronounced yahm-ul) resembles markup languages like XML and HTML. Technically, however, it's a data serialization language, not a markup language. The reason why is that YAML doesn't "mark up" text; it just defines data values. You wouldn't use YAML to tell a web browser how to display text, but you could use it to define configuration options for an application you're deploying.

With YAML, you can define virtually any type of configuration parameter and assign them values. For example, a chocolate cake recipe expressed as YAML might look like this: 

recipe:
  ingredients:
    - flour: 2 cups
    - sugar: 1 1/2 cups
    - cocoa powder: 3/4 cup
    - baking powder: 1 1/2 teaspoons
    - baking soda: 1 1/2 teaspoons
    - salt: 1/2 teaspoon
    - eggs: 2
    - milk: 1 cup
    - vegetable oil: 1/2 cup
    - vanilla extract: 2 teaspoons
    - boiling water: 1 cup
  bake:
    - temp: 350F
    - Time: 25 minutes

As you can see, the first line of this code defines the purpose of the file — specifying a recipe. Then, a set of indented lines define the names and values of ingredients for the cake. Following this is a section containing details about how to bake the cake.

Related:White House Calls for Adoption of Memory-Safe Programming Languages to Prevent Cyber-Attacks

You can follow these same principles to define configuration data for an IT system. If you're configuring a Pod for Kubernetes, for example, you can use YAML to specify which containers the Pod should run, which network ports should be open on the Pod, and so on.

YAML example

Benefits of YAML

YAML has been around since 2001. But it has become popular only over the past decade or so, due to reasons like the following:

  • Adoption by Kubernetes: Kubernetes, the massively popular open source orchestrator, typically uses YAML code to define application deployments.

  • Simple indentation: YAML uses an indentation structure that is similar to the one deployed by languages like Python.

  • Readability: In addition to feeling familiar to Python coders, YAML's indentation rules help keep code easily readable.

  • Versatility: Because YAML supports virtually any type of data object and associated value, you can use it almost anywhere. Unlike languages like HTML (which is mostly associated with the web), YAML isn't suited to just one type of domain. 

So, if you like Kubernetes, Python, and easily readable code, you'll like YAML.

How to Get Started with YAML

YAML's simplicity means that learning it is easy enough, especially if you already have a  basic understanding of markup languages and the concept of using code to define configurations.

A great way to start wrapping your head around YAML is to look at some real-world examples of YAML files. For example, most of the sample configurations you'll find in the Kubernetes documentation use YAML. You can also experiment with using generative AI to produce basic YAML code. This is one of the tasks where chatbots like ChatGPT excel.

From there, experiment with writing your own YAML code from scratch. You can use tools such as this YAML linter to validate your syntax and make sure you're not making common YAML mistakes (like forgetting to indent your code properly).

To get closer to real-world YAML use, consider setting up a lightweight Kubernetes cluster on your laptop or PC, then configure and deploy applications using YAML. If you can get Pods and containers up and running with YAML code, you're well on your way to becoming a YAML pro.

Conclusion

Not everyone needs to know YAML today — but given the popularity of the language, as well as its importance in the context of Kubernetes and other cloud-native computing platforms, YAML skills are increasingly important in many IT jobs today.

Read more about:

Technical Explainer

About the Author

Christopher Tozzi

Technology analyst, Fixate.IO

Christopher Tozzi is a technology analyst with subject matter expertise in cloud computing, application development, open source software, virtualization, containers and more. He also lectures at a major university in the Albany, New York, area. His book, “For Fun and Profit: A History of the Free and Open Source Software Revolution,” was published by MIT Press.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like