Hi let us understand about yaml file, within kubernetes we will be defining
every object using this yaml that's a declarative way of defining how that
particular object should behave and what are all its properties. Of course we
do have other formats as well like XML or Json and comparatively yaml is much
easier to understand for the human as well as for the computer systems
understanding of the basics of yaml is much important because we are going to
define every object for our demo using this yaml file. Yaml it's very simple where
I am going to have collection of key-value pairs. When I say collection of key-value
pairs it's like a map where a key is going to be a string and value could be
anything right from a string or integer or it could be another complex object like a
collection or in fact another map as well. Let's go over a few samples that's going
to give us some clarity. In this particular example I do have a collection of map
that is a key value pair with API version as key and V1 as value. The same way I do
have another key value pair where kind is a key and value pod. Now instead of this
particular value I can have another collection as well, the entire yaml file
works based on the alignment of the text where I am going to have a regular
interval between the text intent within the yaml file. Say for example within this
particular file I do have two spaces and that particular aligned collection is going
to be a child element for this particular element. Let's go over another sample
here I do have a key value pair api version V1 kind as a key and pod as
value. The next key is going to be metadata which is going to have another
map as value and map is going to have a collection of key value pair, where name is
the key my-site is value, if you look at only this particular block entire map is
going to be a value for this particular key metadata and within this particular key
value pair the first element that is name and my-site is one record within the map
and name is the key my sight is value and within the labels key I'm going to
have another map as value. So app a web and I may have some more
additional elements or may not. So this is an example of having another map as the
value within a key like this I can have any combinations where I can have map of
maps, maps of list, list of lists and lists of maps. Now let us understand how a list
going to be. For any key I may want to represent a collection of values, say for
example when I want to expose a collection of ports, I may give collection
saying these are all the ports I want to expose or I may want to pass a
collection of arguments. These are all the arguments I want to pass it as a
collection. So for a key args I'm going to pass four values that will be marked with
a dash and all the dash will be arranged in the same intent. Now let us go over this particular
yaml file where I do have a key value pair api version and v1 this is one key value
pair and next to that we have another key value pair kind as pod and the next we
have the key metadata and the value is this, what this particular value going to
have, that's going to have name as the key my-site as value and the next key is
labels that's going to have a child key and value pair. Now let's look into this
specific key, the fourth key that is specs of the entire yaml file, that's going to
have a key containers. That's having a collection the first element is a map
and the second element is another map, within the map I do have a key value pair
name as the key front-end as value. Then I do have images key and I do have value
then I have ports within that I do have a collection, within the collection I have
mentioned what is the container port and the other details will follow with a dash.
So we have seen four major parts that is key that's going to be a string always and
I'm going to have a value. Value could be any type and it could be a simple string
or an integer or it could be another complex object like a map or a collection
and every element within that particular map can have another inner complex
object. So if you look at yaml file as just key and a value, value could be any
complex object then the things going to be very simple. If you consider any yaml
file that's going to have key-value pairs. If you look at this particular example I do
have a yaml file and I do have a collection of representation of the
objects, every object will be represented using these four important keys
api version kind metadata and its specification. Here I do have a kind called
service and the version is v1, so I do have a key value pair, api version and
values is v1 the kind is the key and value is service then I do have a key as
metadata within that I do have a map and how many keys are there, name as one
key, labels as another key. Name it is having a text and labels is having another
map, that map is having three key value pairs and the keys are app, tier and role.
So if you look at any yaml file this is how the structure going to be, let's have an
understanding on this specific structure, I do have a key value pair api version as
the key apps/v1 as value and the comment within the yaml file will be
represented using a hash symbol and the next key value pair is kind as the key
deployment as value, metadata is the key and that is having a key value pair as a
value which is having one key value pair name and front end. Then I do have spec
spec is having selector as one key, replicas as other key, template as another
key. So everything is represented using this same intent, within template I do
have a key called metadata and spec, within metadata I do have a key called
labels that is going to have two key value pairs, app as the key and tier as the
another key. The same way I can decode any yaml file and we will be representing
every object within the kubernetes session as the yaml file and the entire
yaml file will also be uploaded as a part of the session, so that you don't need to
code the yaml file but always it is a good idea to have a thorough understanding on
the yaml file, so that any changes to the yaml file we can do it over the text file
as well and there are n number of online yaml validator, where you can validate
whether it is following the right syntax or not. So in a quick summary we had seen
what is the yaml file and how the syntax is being followed within the yaml file and
we saw a few samples as well how the keys and values
will be represented within the yaml file.