Kunal's Yaml Tutorial Notes
Kunal's Yaml Tutorial Notes
👉
source kunal’s yaml course
Course Content
Introduction
Syntax
Properties/ Data types
Yaml Tools
Introduction
Yaml ( Was Known as Yet Another Markup Language . But now it is known as
Yaml ain’t markup language )
Markup language - ( eg html ) A markup language is a computer language that
uses tags to define elements within a document. It is human-readable, meaning
markup files contain standard words, rather than typical programming syntax.
While several markup languages exist, the two most popular are HTML and XML.
Yaml Basics
→ Yaml isn’t a programming language but it is a data format used to exchange
data
→ Similar to XML and JSON
→ Simple human readable language used to represent data
→ Yaml can only store data but not commands
Data serialization
Storing of data in files is known as Data Serialisation. Data serialization is the
process of converting an object into a stream of bytes to more easily save
or transmit it .
Data object present in each device platforms/applications differ from one another
so when this data object is needed to transferred between devices/applications
data Serialization enables us to save the state of an object and recreate the
object in a new location
Yaml 1
Data Serialization languages - Language that is used to represent an object
in text format
eg :- YAML , JSON , XML
Store data in form of code and then using this to convert it in to an object
obj → file ( Serialization )
file → obj ( Deserialization )
Yaml is
→ Used in configuration files ( kubernetes )
→ Used in logs and caches etc
Benefits of yaml
→ Simple and easy to read
Yaml 2
→ It Has a strict syntax - Indentation is important
→ Easily convertable to JSON , XML
→ Most programming languages uses YAML
→ More powerful when representing complex data
→ Various tools are available like parser
→ Parsing of data is easy
Syntax
Yaml Stores data in key value pair
Yaml is case sensitive
Yaml does not support multiline comments
"apple" : "I am a red fruit"
1 : "This is Bharath's role number"
Lists
#lists
- apple
- mango
- banana
- Apple
Yaml 3
How yaml differentiates different documents in a yaml file
→ By using --- to separate different documents in a sigle yam file
Properties/Data types
#name : type
#types - strings ( can be represnted with double , single or no quotes),
name : bharath
job : "swe"
title : 'Software devloper'
Yaml 4
#multiline string use |
bio : |
My name is Bharath Subramanya.
I am a great guy
#string
name : !!str "bharath"
#boolean
isTrue : !!bool true
#null
sur : !!null Null # or null Null ~
~ : this a keyname
{
"name": "bharath",
"job": "swe",
"title": "Software devloper",
"bio": "My name is Bharath Subramanya.\nI am a great guy\n",
Yaml 5
"message": "Hey it me bharath subramanya . I am currently learning Devops\n",
"marks": 89.9,
"boioleanValue": "No",
"zero": 0,
"positiveNUm": 45,
"negativeNum": -45,
"binary": 25,
"ocatal": 226,
"hexa": 69,
"commaValue": 50000,
"expontentinal": 6.023e+56,
"marks2": 56.89,
"infinity": null,
"notANumber": null,
"name2": "bharath",
"isTrue": true,
"sur": null,
"null": "this a keyname",
"date": "2002-12-14T00:00:00.000Z"
}
stdudent : !!seq
- name
- rool_no
- mark
#Nested sequence
-
- coimbatore
- chennai
- theni
-
- apple
- mango
- banana
-
- none
-
- super
Yaml 6
#nested map
name : bharath
role :
age : 20
job : studrnt
role2 : { age: 21 , job : student}
#dictionaries !!map
people : !!map
- Bharath :
name : Bharath Subu
age : 20
- Hari :
name : Hari
age : 21
liking : &base
fav : mango
not fav : grapes
person1 :
name : Bharath
<<: *base
person2 :
name : hari
<<: *base
JSON equivalent
[
"hair",
"nose"
]
Yaml 7
{
"stdudent": [
"name",
"rool_no",
"mark"
]
}
{
"sparse seq": [
"hey",
"how",
null,
null,
"sup"
]
}
[
[
"coimbatore",
"chennai",
"theni"
],
[
"apple",
"mango",
"banana"
],
[
"none",
null,
"super"
]
]
{
"name": "bharath",
"role": {
"age": 20,
"job": "studrnt"
},
"role2": {
"age": 21,
"job": "student"
}
}
{
"pair example": [
[
"job",
"student"
],
[
"job",
"learner"
]
Yaml 8
],
"pair example2": [
[
"job",
"student"
],
[
"job",
"learner"
]
]
}
{
"names": {
"kunal": null,
"bharath": null,
"hari": null
}
}
{
"liking": {
"fav": "mango",
"not fav": "grapes"
},
"person1": {
"name": "Bharath",
"fav": "mango",
"not fav": "grapes"
},
"person2": {
"name": "hari",
"fav": "mango",
"not fav": "grapes"
}
}
Yaml 9
In xml
- Not easily readable by humans
In JSON
Yaml 10
In YAML
Can be easily converted using json to yaml https://www.json2yaml.com/
Yaml Tools
When we work with large files we have to make sure that our YAML files are
validated .
blog link :
Yaml 11
How to validate Kubernetes YAML files
In the previous article, we have learned how to create
Kubernetes YAML files. Now, let's see how to ensure that the
files we have created are not only valid YAML but more
https://itnext.io/how-to-validate-kubernetes-yaml-files-9a
17b9a30f08
Datree
website link :
Monokle
Helps in managing a large number of yaml files
website link : https://monokle.io/
Lens
Uses Graphical interface to ease the creating of yaml files
Website link :
Yaml 12