What is YAML?
YAML is a data serialization language, like XML and JSON.
What is a serialization language?
Applications written with different technologies and languages, which have different data structures, can transfer data to each other on a common grid or standard format.
Ex: JSON, YAML, XML.
YAML is not — yet another markup language.
- "Human friendly" data serialization standard for all programming languages
- Syntax: strict indentation
- Store the config file with your code, or in its own git repo.
File extension: .yaml and .yml
YAML Format Compared to Others:
- Human readable and intuitive
- Line separation & indentation
- YAML use cases: Docker Compose files, Docker, Kubernetes, Ansible, Prometheus — a great fit for writing configuration files for all these recent DevOps tools
YAML identification:
- Line separation
- Indentation
YAML vs XML vs JSON
YAML is a superset of JSON — any valid JSON file is also a valid YAML file.
Basic Syntax of YAML:
Key Value Pairs:
# Comment use
app: user-authentication
port: 9000
version: 1.7
Objects:
By indenting the key value pair and indenting by objects:
microservice:
app: user-authentication
port: 9000
version: 1.7
Lists:
microservice:
- app: user-authentication
port: 9000
version: 1.7
Boolean Values:
microservice:
- app: user-authentication
port: 9000
version: 1.7
deploy: yes, no, on, off, false, true
More Lists:
microservice:
- app: user-authentication
version: [1.7, 2.1, 8.1] # → string
port: 9000
Kubernetes YAML Files:
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx-container
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: nginx-vol
mountPath: /usr/nginx/html
Key value pairs breakdown:
- metadata = object
- labels = object
- spec = object
- containers = list of objects
- port = list
- volumeMounts = list of objects
Top comments (0)