In k8s, yaml format files are generally used to create pods that meet our expectations. Such yaml files are generally called resource lists .
yaml description
It is a highly readable format used to express data sequences. yaml: It is still a markup language, but to emphasize that this language is data-centric rather than markup language.
Basic grammar
- Tab key is not allowed when indenting, only spaces are allowed.
- The number of spaces for indentation is not important, as long as elements of the same level are aligned to the left.
- # Identifies a comment. From this character to the end of the line, it will be ignored by the interpreter.
Data structure supported by YAML
- Object: A collection of key-value pairs, also known as a map/hash/dictionary
- Array: A set of values arranged in order, also known as sequence/list
- Scalar: a single, indivisible value
Object type
A set of key-value pairs of the object, represented by a colon structure
name: Tom
age: 18
Yaml also allows another type of writing, writing all key-value pairs as an inline object
hash: {name: Tom, age: 18}
Array type
A set of lines at the beginning of the conjunction line to form an array
animal
- cat
- dog
Arrays can also use inline notation
animal: [cat, dog]
Composite structure
Objects and arrays can be combined to form a composite structure
language:
- Ruby
- Perl
- Python
websites:
YAML: yaml.org
Ruby:ruby-lang.org
Python:user.perl.org
Scalar
Scalars are the most basic and indivisible value. The following data types are scalar
- Numerical value: directly expressed in literal form
number: 12.30
- Boolean value: represented by true and false
isSet: true
- null: represented by ~
parent: ~
- Time: in ISO8601 format
iso8601: 2017-07-10T10:13:47.861Z
- Date: The year, month, and day are expressed in compound iso8601 format
data: 1976-01-01
YAML allows two exclamation marks!! Coercion data type
e: !!str 123
f: !!str true
- String
Strings do not use quotation marks by default. If the string contains spaces or special characters, they need to be enclosed in quotation marks. Both single and double quotation marks can
be written in multiple lines. There must be a space indentation from the second line ,
Line breaks will be converted to spaces. For multi-line strings, you can use | to keep the line breaks, or use> to fold line breaks
+ to keep the line breaks at the end of the text block, and-to delete the line breaks at the end of the string