Hi, Let us understand about Named template. As we discussed earlier
We used to keep the templates as a part of the templates folder and most of the files within the templates
folder are treated as kubernetes manifest.
And that is one exception where I can have nodes.txt and I can
have other files as well which is going to start with underscore.
If you remember earlier, when we are creating the charts, by default it was creating some sample files,
it had underscore and I can have multiple templates in the same file and I can give a name to it and
use it elsewhere as well that's what we are going to learn in this particular lecture.
where I can define a template and give a name to it and include this particular template in other locations as well.
This will help us to leverage the reusability. Let us understand by doing some demo.
Let me open the template file.
Here, I'm going to delete all the labels and include that as a predefined template and I can have the
templates as a separate file with underscore as a prefix.
or I can include it in the same file as well. To start with
I'm going to include in the same file. Here
I'm going to have a template where I'm going to define the name of the template as
mychart.system labels and it's supports the syntax of using the namespaces as well.
And it's going to have this particular syntax. And what needs to get included I can include over here.
This works very similar to the include or import that we use in the other programming languages.
Now, let me include this particular template.
that is mychart.system labels within the actual template. Here
I'm going to include. Now, let me do the dry run. So what happened
It automatically included the labels and it's not listing the actual template that we had defined within
the manifest file. If you observe one thing very carefully, let me get into the configuration file.
where we have provided this particular template and
This is having proper alignment and wherever
I'm going to include this particular alignment will not be considered when I'm going to include using
the keyword template. There is another option using include that we will be seeing it later.
And this particular include is not going to consider this particular space.
I can go ahead and delete them as well. Let me delete them.
And do the dry run. This is also producing the same result. So within the template
The important thing to remember is the space or indentation within the inner template and not in the place
where we are going to include the template using that template keyword.
The reason why I am concentrating on the indentation, while doing the template programming for the yaml file
the indentation is where most of the mistakes used to happen.
So in a quick summary we have seen how to create a template and include that within another template.
The next section we are going to see how to have this particular template
In a separate file and include within another template file.