Back to blog

Aug 15, 2022

Everything You Wanted to Know About Comments in YAML

Its human-friendly syntax has fueled the widespread use of YAML in configuration files. In particular, a thorough understanding of handling these files is helpful if you work with Kubernetes.

Everything You Wanted to Know About Comments in YAML

Commenting in YAML files

Its human-friendly syntax has fueled the widespread use of YAML in configuration files. In particular, a thorough understanding of handling these files is helpful if you work with Kubernetes. Kubernetes manifests are written using the YAML format and you can save a lot of time by being a YAML pro. To that end, we will answer frequently asked questions regarding comments in YAML files.

How to add comments to YAML files?

Adding YAML comments is simple. In fact, it's similar to how comments work in bash scripts. You just have to use the hashtag symbol (#) at the beginning of the line you want to comment on.

# Source file (this is a comment)
file:
  - sample.yaml

If you want to comment out multiple lines in YAML, you just have to use a # at the beginning of each line.

Can you add comments to the YAML files used with Kubernetes?

The short answer is yes; you can add comments to YAML files used with Kubernetes. That said, the API server won't be able to process such comments. After all, the whole point of comments is that they are ignored!

Therefore, in many cases, you should use Kubernetes annotations instead of comments.

Your customers dread downtime. Let's make it a thing of the past.