Do you know all the YAML tricks and gotchas?

Are there any YAML tips for Kubernetes?

Read along!
1/

Let's cover the basics first.

YAML has three basic rules:

1. Indentation — only 2 or 4 spaces
2. Maps — key-value pairs
3. Lists — collections of things
2/

Maps and lists are the basic building blocks of any YAML file.

Any value that is part of a list or of map's value can be a string, a number, a boolean, `null`, or another dictionary.

In most cases, strings don't require quotes.

But sometimes if you miss them... 💣💥
3/

Apart from edge cases, there are some actual useful features if you write Kubernetes manifests:

- You can use `---` to delimit docs
- You can define snippets with `*` and reference them with `&`
4/

What if you make a mistake?

How do you know? 🤔

You could use:

1. an online YAML linter like http://www.yamllint.com/ 
2. a CLI like https://yamllint.readthedocs.io/en/stable/ 
3. if you use Visual Studio Code, install the YAML extension from Red Hat for autocomplete https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml
5/

Is there any useful tool to edit YAML other than by hand?

`yq` https://mikefarah.github.io/yq/  is a command-line tool designed to transform YAML.

It is similar to another more popular tool called `jq` that focuses on JSON instead of YAML.
6/

That's it! This was a short intro to YAML (and YAML's gotchas). Do you know more tips? Let me know!

You might enjoy the previous threads too! You can find all of them here: https://twitter.com/danielepolencic/status/1298543151901155330

What would you like to see next? Please reply and let me know!
You can follow @danielepolencic.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.