appendix-b

Appendix B. Basics of YAML

 

YAML ( "Yet Another Markup Language") is a human-readable data serialization format. It's often used for configuration files and data exchange between languages with different data structures. In Kubernetes, YAML is used for defining configuration files that describe the desired state of Kubernetes resources. These configuration files are then used with the kubectl command-line tool to create, update, or delete resources in a Kubernetes cluster. Hence it's quite important to learn a bit about YAML.

B.1 Basic YAML file

A basic YAML file consists of key-value pairs and may include lists and nested structures. Below is an example of a simple YAML file, which we will use to understand the YAML format.

#YAML comment
name: John Doe
age: 30
is_student: false
grades:
  - subject: Math
    score: 95
  - subject: English
    score: 80
address:
  city: "New York"
  zip: 10001
  country: USA

Comments:

Comments start with the # symbol and are ignored by parsers. They are used for adding explanatory notes in the file.

Scalar Values:

Key-value pairs consist of a key followed by a colon and a space, then the corresponding value.

Scalars can be strings, numbers, booleans, or null.

name: John Doe
age: 30
is_student: false

Lists:

Lists are denoted by a hyphen followed by a space (- ). Each item in the list is indented.

grades:
  - subject: Math
    score: 95
  - subject: English
    score: 80

Nested Structures (Maps):

B.1.1 Data Types in YAML

B.2 Aliases and Anchors

B.2.1 References (Merging and Reusing Data)

B.2.2 Complex Data Types

B.2.3 Custom Data Types

B.2.4 Block Style vs. Flow Style

B.2.5 Key Sorting and Case Sensitivity

B.2.6 Best Practices