[go: up one dir, main page]

0% found this document useful (0 votes)
296 views12 pages

Kunal's Yaml Tutorial Notes

This document provides an overview of YAML, including its history, basics, data types, syntax, and tools. YAML is a human-readable data serialization format commonly used for configuration files. It allows storage of lists, maps, and other complex data types through indentation and specific syntax. The document covers YAML's advantages over other formats like JSON and XML in terms of human readability and representation of nested and complex data structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
296 views12 pages

Kunal's Yaml Tutorial Notes

This document provides an overview of YAML, including its history, basics, data types, syntax, and tools. YAML is a human-readable data serialization format commonly used for configuration files. It allows storage of lists, maps, and other complex data types through indentation and specific syntax. The document covers YAML's advantages over other formats like JSON and XML in terms of human readability and representation of nested and complex data structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Yaml

👉
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 )

Why did the acronym of YAML Change ?


we know than an markup language is used to store documents , but in YAML
we can store not only document but also object data also .

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

Yaml is used heavily in kubernetes

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

Complex data types like key : [ list]


cities:
- coimbatore
- theni
- chennai

Indentation is extremely important


the above datatype can also be defined as
cities : [coimbatore , theni ,chennai]

Converting Yaml document into Json


👉  tool

Yaml 3
How yaml differentiates different documents in a yaml file
→ By using --- to separate different documents in a sigle yam file

In yaml we can end a document using …

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

#write a single line in multiple lines


message : >
Hey it me
bharath subramanya .
I am currently learning
Devops

#yaml will automatically detect the data types


number : 567
marks : 89.9
boioleanValue : No # n, N , false , False , FALSE
#same for true -> yes , y , Y

#specify the type


# !!__dataType__ to specify the data type
zero : !!int 0
positiveNUm: !!int 45
negativeNum : !!int -45
binary : !!int 0b11001
ocatal : !!int 0657
hexa : !!int 0x45
commaValue : !!int +50_000 #50,000
expontentinal : 6.023E56

#floating point numbers


marks : !!float 56.89
infinity : !!float .inf #infinity
notANumber : .nan #not a number

#string
name : !!str "bharath"

#boolean
isTrue : !!bool true

#null
sur : !!null Null # or null Null ~
~ : this a keyname

#date and times


date : !!timestamp 2002-12-14
#if no timezone is specified UTC is added

Equivalent JSON format

{
"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"
}

Advanced Data Types

#list are written in sequence


- hair
- nose

stdudent : !!seq
- name
- rool_no
- mark

#some of the keys of the sequence may be empty


#this is known as sparse sequence
sparse seq :
- hey
- how
-
- Null
- sup

#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}

#pairs : key may have duplicate values


#!!pairs
pair example : !!pairs
- job : student
- job : learner
#or
pair example2 : !!pairs [job : student , job : learner]
#this will be an array of hashtables

#!!set will allow us to have unique values


names : !!set
? kunal
? bharath
? hari

#dictionaries !!map
people : !!map
- Bharath :
name : Bharath Subu
age : 20
- Hari :
name : Hari
age : 21

#reusing some properties using anchors


# &__anchor tag__ - defines what to copy
# <<: *__anchor tag__ - defines where to paste

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"
}
}

How data is stored in xml ,JSON ,yaml


Data to be represented

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 :

Combat misconfigurations | Datree


Datree is a CLI solution that supports Kubernetes owners in
their roles, by preventing developers from making errors in
K8s configurations that can cause clusters to fail in
https://www.datree.io/

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 :

Lens | The Kubernetes IDE


Chris Kalmer@chriskalmar Here's a nice and free desktop
app that will help you visualize and control your Kubernetes
cluster(s). 🐳 I know how overwhelming managing a k8s
https://k8slens.dev/

Yaml 12

You might also like