The YAML Files

The YAML Files

YAML

YAML is an information transfer language like JSON or XML. And it is used for its simplicity and consistency.

File Extention

These YAML files end with .yml or .yaml, either of them is correct.

Indentation

The indentation in YAML is essential, to make an indentation valid you need to use 2 spaces per indentation. Indentation is used instead of curly brackets {}.

Syntax

You don't end the line with a ; or any other special character.

Comments

Use the # symbol to ignore whatever it is in front of this symbol until the end of the line.

# variable: string commented
valid: "not commented"

Objects

You use indentation to denote that the variables below are methods of the object. YAML is sensitive to indentation so they all need to be at the same level of indentation.

nameoftheobject:
  app: some-name
  port: 9000
  version: 1.7

Lists

Use the - symbol to make a list, remember to indent the variables that belong to that list. But you can also avoid indentation while using lists, so don't get confused when you see them in different forms of indentation. But all elements need to have the same indentation.

microservices:
  - app: some-name
    port: 9000
    version: 1.7
  - app: other-name
    port: 9002
    version: 1.9
microservices:
  - some-name
  - other-name
  - app: dog
    port: 19
    versions:
    - 1.2
    - 1.5
    - 1.8

You can also use brackets as a primitive.

microservices:
  - some-name
  - other-name
  - app: dog
    port: 19
    versions: [1.2, 1.5, 1.8]

Boolean

true false yes no on and off, all of them are used as boolean values.

Multiline strings

Use the | symbol to make separate lines, and use the > symbol to make a single line of the string.

multilineString: |
  This string is separated
  so there is no need to make a buzz
  this is how it will be shown
multilineString: >
  This line will be shown as
  one line, no matter how long
  or how many breaks do I make

Environment Variables

Use the $ before the name of the environment variable to use it.

command: mysql -h 123.000.000 -u root $THIS_IS_A_PASSWORD -e 'SELECT 1'

Placeholders

Use the double curly brackets {{}}to use placeholders for templates.

app: {{ .Values.service.name }}

Multiple YAML Files

Use three dashes --- to separate YAML files inside the same file.

thisIsAVariable: blah-blah-blah

---
thisIsAnotherFileInside: this-is-another-file

Well, that's it for now. I hope it was useful for you. Comment if you have any other suggestions or something to add, I'll be reading you.

Follow me on Twitter, LinkedIn, Instagram, Github, Medium (For more opinion-based posts), and here on Hashnode and my Hashnode blog.

Have a nice day and until next time. Bye.