Yaml indentions in k8

Can someone point me to some documentation that explains the indentations for kubernetes objects, files, etc.

I am not understanding when, why and, how to indent.

IBM’s developer site has a nice introduction to YAML; it covers the basics. Some points:

  1. You can think of YAML having
  • scalars (akey: "a value")
  • lists
nameOfList:
  - item1
  - item2
  - item3
  • dictionaries
  nameOfDictionary:
     key1: val1
     key2: val2
     fred: another key

Indentation reflects when something like a list is inside of a dictionary, or a list of dictionaries. But the key to getting indentation right is to learn what the various parts of the YAML file are doing – are they list of items? Are they objects/dictionaries with keys? Are they just scalars with a single value? But you intent when you are adding items of a list, or keys to a dictionary.

The other rules is: in a list or a dictionary, everything at the same level needs the same indentation. It doesn’t matter how much, although I think it’s a best practice to be consistent – always use spaces and never use tabs, and use two spaces per indentation level.

1 Like

@andrew-reichek Please also see https://github.com/kodekloudhub/community-faq/blob/main/docs/yaml-faq.md

1 Like