YAML Basics
Document, Mapping, Sequence, and Scalar are the four basic types of YAML documents.
This document is not a tutorial on YAML, but rather a brief overview of the YAML terminology in Anemos context. For more information on YAML, please refer to the YAML specification.
Document
A YAML document in Anemos is a file that contains the representation of a Kubernetes resource such as a Pod, Deployment, or Service.
Technically, a YAML file can contain multiple documents, separated by ---
. However, Anemos only supports
one document per file. Furthermore, even though a YAML document can have a Mapping,
Sequence, or Scalar as its root, in Anemos, a Document
can only have a Mapping as its root.
An example of a YAML document:
apiVersion: v1
kind: Pod
metadata:
name: my-pod
namespace: default
spec:
containers:
- name: my-container
image: nginx
ports:
- containerPort: 80
Mapping
A mapping is a collection of key-value pairs. Each key is unique within the mapping. Key of a mapping is a Scalar. The value can be a Mapping, Sequence, or Scalar.
# The value of key1 is a scalar.
key1: value1
# The value of key2 is another mapping.
key2:
subkey1: subvalue1
subkey2: subvalue2
# The value of key3 is a sequence.
key3:
- item1
- item2
Sequence
A sequence is an ordered collection of items. Each item in a sequence can be a Mapping, Sequence, or Scalar. It is possible to have multiple types of data in a single sequence.
# Scalar item.
- item1
# Mapping item.
- item3:
subitem1: subvalue1
subitem2: subvalue2
# Sequence item.
- item4:
- subitem1
- subitem2
Scalar
A scalar is a single value. It can be a string, number, boolean, or null. Scalars have styles that define how they are represented in YAML.
# Plain style
key1: value1
# Double-quoted style
key2: "value2"
# Single-quoted style
key3: 'value3'
# Literal style
key4: |
This is a literal style
that preserves line breaks
and indentation.
# Folded style
key5: >
This is a folded style
that combines multiple lines
into a single line.