Yaml Tutorial | Learn YAML in 18 mins

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I will explain all about demo we will see what ml is used for and we'll go through the syntax of how to write a valid ml file as you've seen in my tutorial videos about docker kubernetes in Siebel Prometheus etc I have shown example configuration files all written in mo because it has become a pretty widely used format for writing configurations for many different DevOps tools and applications that's why when using these tools it's important to understand the details of yellow syntax and its main concepts generally speaking yeah mo is a serialization language just like XML and JSON serialization language basically means that applications written with different technologies languages etc which have different data structures can transfer data to each other using a common agreed-on or a standard format and the most popular such formats are llamo jason and xml and the name llamo actually stands for y mo ain't markup language and you can create llamo file with one of those two extensions they're the same one of the main reasons of why hemos popularity has increased so much over the past years is that it's super human readable and intuitive which makes it a great fit for writing configuration files for all those recent DevOps tools like I mentioned docker kubernetes etc so to show you an example and also comparison between llamo XML and JSON formats let's consider this example so this is how y mo file would look like it's very straightforward it's pretty clean this is the same data in XML format where you have this so-called text and then you have the JSON format and as you see in XML and JSON data structures are defined using special characters in XML you have so-called text with angle brackets in Jason you have curly brackets and in yellow you don't have those special characters so how data structure is defined in the mo is through line separations and spaces with indentations that's why you can indent in space in XML and JSON as you wish but in the ml you get validation error if you have one single space and data structure wrong which may be a little bit annoying but it makes llamó format the cleanest most human readable format of all three so what are some of your most use cases to count few yema format is used for duck composed files for NZ ball prometheus kubernetes and many more tools okay so now that you know what llamo is and where it's used let's dive into its syntax so it started with the basic syntax which is simple key value pairs so let's take an example that I just showed you and let's write key value pairs like AB and let's call it user authentication and we have a port let's put it at 9000 and version of the app and 1.7 just an example so these are simple key value pairs this whole yellow file is written and you have different datatypes here we have a string which note that we don't have to enclose it with quotes you can if you want to so you can use either double quotes or single quotes or no quotes at all and you have the number of representations as well if you need to use some special character like line carriage for example then you have to enclose it in strings otherwise Yemen cannot recognize it but other than that you don't need quotes so I'm gonna mention here that in yellow you also have comments so everything that starts with this sign or with this character basically yellow interprets as a comment so I can write comment here and basically I can use this comment between the attributes anywhere in the mo file where I want to make my file even more readable and understandable so this is a simple list of key value pairs what you can do is you can group them inside of an object so you can create an object in yellow and you can do that by in in this individual key value pairs and enclosing it in an object let's call it a micro service like this and this becomes an object with micro service with its attributes and note that the space has to be exactly same for each attribute within the object and also note that because Jemil is so sensitive about the spaces and indentation it's always a good idea to use a llamo validator before you for example execute a configuration file in kubernetes or you apply that or use that file to be sure that your invitations are right and there are online tools for that one of them which I use is this one here but there are some other online tools as well I can link them in description so what you can do is you can just copy that and it tells you that it's valid if I for example this it's gonna scream that indentation so you can check your valid et here so let's go back in yellow you can also have lists so for example if you have multiple micro services like this I can create a list of those micro services simply by using - so like this and again important thing that those attributes stay at the same level and the - is right here you can also have boolean values so for example if we have deployed attributes you can say true or false and in Yemen you can also express boolean expressions with yes or no so let's say deployed yes and also with on and off so all these 3 pairs of values are expressions of boolean values and you also see the syntax highlighting is different so this is a list and these are the items of the list and I can add second item app let's say shopping cards whatever and let's say port is nine thousand two then we have version which is 1.9 and this way you can define lists of objects but you can also define lists of simple values so for example if you had a list of just the micro-service names you could do like this and that would be fine as well and you can also use lists inside of a list item for example if you have multiple versions of a shopping cart for example that you want to list here for some reason I don't know you can actually list them here so I can do versions let's say you have 2.0 and then you have 2.1 etc and i'm gonna copy that also in the validator and here you see that the - position you can actually use different annotations for that so i have an indentation here but I don't have here so that's fine as well I could do like this or I can align it on the parent of attribute so don't be confused if you see different alignments of the lists both work because llamo recognizes that it's a list item what will not work is if you don't align the list items using indentation so for example it was one space off then the validator will be red so some small details there also know that if you have primitive items in the list like this one for example some not the object items but the primitive ones you can also express it in different way and this is how with the different syntax you have square brackets and you can put those values inside like a list which makes it actually more readable if you have just simple datatypes and not objects let's validate that as well to make sure you can have strings here as well or mix of them doesn't matter now this is really some of the basics of llamo syntax so to make it more practical and realistic let's actually look at real kubernetes yellow example to see how these basic syntax is expressed there so I'm gonna clean this up and let's look at a pot configuration so this is basically the main part where the metadata and kind etcetera is defined as you see these are super simple key value pairs and then you have these objects that we just saw with Hiroki or the indentations to have a metadata object and inside that you have another labels object and here you have the specification and containers maybe you are familiar with this already and in containers is a list so each container item sort of say has to start with - and indentation and then we have the name of the container have the image let's use nginx then you have ports which is another list so again we start with - to list ports and then you have the attribute which is container port value there inside container you also can have volume mounts which is another list so here you list all your volumes and this is a list of objects again we have key value pairs let's use I don't know nginx volume and mount path some example and this is how a pod configuration will look like so you have again basic building blocks key value pairs objects and lists and then lists inside of that list item and since containers is also at least you can have multiple containers inside and for example if I were to define a sidecar container I would have another item expression - and here I would say this is my sidecar container and again image some image etc also another example that I also showed in one of my videos is where we deployed a curl image as a sidecar and inside of that container configuration wheels had these two lines I'm actually gonna copy them and here you see that this is this alternative syntax of defining lists so arguments is a list and we use it like this and then we have the two items here one and two so knowing how yellow syntax works should make it easier to understand the kubernetes configuration file structure better another important concept of Gemmell syntax is when you have multi-line strings so for example file contents multi-line string let's call it the attribute and instead of writing this multi-line string here with the carriage I can write it actually on multiple lines like this so I don't need that thing anymore so this is a multi-line string and this is the next line etc right and the way I can do that is using the pipe symbol so yellow will see that character and will interpret everything here as a multi-line text so this line breaks will actually stay another case could be if you have this super long string which has to be on a single line so for example this is a single line string that should be all on one line and some other stuff let's put dots here and in that case obviously you want the line carriages here but you also don't want to write this all out on one line because it's just not very readable and that's why you want to for readability you still want to display that here in my demo file itself but you want yellow to interpreted as a single line in this case instead of pipe you actually replace it with a greater than sign or with this angled bracket and this will be interpreted as single line now this is just some random example so let's actually see some real use cases I have a config file demo here from kubernetes which I have used in what my tutorial videos and here you see the basic key value stuff and here you have the name of the attribute and call it whatever you want and here we use that pipe and these are actually the contents of the file this is going to be displayed exactly like this with line carriages because this has to be each one on its own line and this way you can actually write configuration files for different applications like this one is for mosquito you also have maybe flu in D and they have their own different formats and you can write the whole thing as a file represented by multi-line string in yellow another example of using this multi-line string that you may actually encounter in communities configuration files is this one right here so this is part of configuration of a pod so you have this command attribute and here you see the familiar list and here again you have this pipe that is followed by a multi-line string and this is an example of bhana that I found so basically what it does is that it executes shell command and this is a shell script so you can actually put the whole contents of a shell script as you would have that as a shell script file after that pipe symbol as a multi-line text and this will execute as a shell script basically one thing that I've also needed to use in ml Wars environmental variables so for example if a part that has environmental variables defined inside and you have to use one of those inside the pod configuration you can actually access them using a dollar sign inside your yellow configuration so this is an example of a my sequel pod and here the same thing that I showed you before see how they comment and here in this line we're executing in my sequel command and I am accessing the environmental variable that is available inside the pod using the name of the environmental variable and the dollar sign before that which if you need that might come in handy because I believe this specific concept of using environmental variables in llamó isn't very well documented Gemmell also has a concept of placeholders one of his use cases is in help for example and this is how it looks like so basically instead of directly writing the values inside you define placeholders and the syntax for using placeholders is double curly braces around that placeholder and this value gets replaced using template generator and I believe the same concept is used in instable as well so again if you use helm or in zville for example and you see the syntax you should know what it stands for and lastly inside one llamó file you can actually define multiple components and you can separate these components using three dishes like this so for example if I have a yellow file where I want to put all my configurations I can separate them using this three dashes and this will be a valid EML and this can be very handy in case especially where you have multiple components maybe for one service and you want to group them in a single yellow file so for that use case this is the way to go maybe the interesting note here is that in all my kubernetes videos I have used the yellow format to write kubernetes configuration files however you can also write commands configuration files in JSON format sample if I head over to my dashboard and I click to edit one of my components I see that I have both llamo and Jason formats available which I can edit directly or if I want to create a new element new component I can provide either yellow or Jason but I personally use yellow because as I mentioned it's cleaner and more readable but you can actually use both so this was it for Gemmell tutorial video thank you for watching and see you in the next video
Info
Channel: TechWorld with Nana
Views: 546,938
Rating: undefined out of 5
Keywords: yaml, yaml tutorial, yaml tutorial for beginners, yaml basics, yaml devops, yaml for beginners, yaml syntax tutorial, yaml syntax, yaml for kubernetes, yaml complete tutorial, yaml advanced, what is yaml, yaml in devops, yaml explained, yaml file, yaml file syntax, yaml introduction, yaml crash course, json vs yaml, yaml tags, mike dane, yaml demo, yaml example, yaml real example, techworld with nana, kodekloud, yaml basics for beginners, learn yaml, devops tools
Id: 1uFVr15xDGg
Channel Id: undefined
Length: 18min 5sec (1085 seconds)
Published: Fri Jun 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.