1
00:00:00,000 --> 00:00:09,400
Hi, Let us understand about Named template. As we discussed earlier

2
00:00:09,400 --> 00:00:14,833
We used to keep the templates as a part of the templates folder and most of the files within the templates

3
00:00:14,833 --> 00:00:18,033
folder are treated as kubernetes manifest.

4
00:00:18,033 --> 00:00:23,199
And that is one exception where I can have nodes.txt and I can

5
00:00:23,200 --> 00:00:27,600
have other files as well which is going to start with underscore.

6
00:00:27,600 --> 00:00:33,466
If you remember earlier, when we are creating the charts, by default it was creating some sample files,

7
00:00:33,466 --> 00:00:40,466
it had underscore and I can have multiple templates in the same file and I can give a name to it and

8
00:00:40,466 --> 00:00:45,799
use it elsewhere as well that's what we are going to learn in this particular lecture.

9
00:00:45,800 --> 00:00:53,100
where I can define a template and give a name to it and include this particular template in other locations as well.

10
00:00:53,100 --> 00:00:58,933
This will help us to leverage the reusability. Let us understand by doing some demo.

11
00:00:58,933 --> 00:01:04,498
Let me open the template file.

12
00:01:04,500 --> 00:01:11,433
Here, I'm going to delete all the labels and include that as a predefined template and I can have the

13
00:01:11,433 --> 00:01:16,099
templates as a separate file with underscore as a prefix.

14
00:01:16,100 --> 00:01:20,100
or I can include it in the same file as well. To start with

15
00:01:20,100 --> 00:01:22,400
I'm going to include in the same file. Here

16
00:01:22,400 --> 00:01:27,566
I'm going to have a template where I'm going to define the name of the template as

17
00:01:27,566 --> 00:01:32,699
mychart.system labels and it's supports the syntax of using the namespaces as well.

18
00:01:32,700 --> 00:01:39,266
And it's going to have this particular syntax. And what needs to get included I can include over here.

19
00:01:39,266 --> 00:01:45,099
This works very similar to the include or import that we use in the other programming languages.

20
00:01:45,100 --> 00:01:47,200
Now, let me include this particular template.

21
00:01:47,200 --> 00:01:52,966
that is mychart.system labels within the actual template. Here

22
00:01:52,966 --> 00:02:04,732
I'm going to include. Now, let me do the dry run. So what happened

23
00:02:04,733 --> 00:02:13,633
It automatically included the labels and it's not listing the actual template that we had defined within

24
00:02:13,633 --> 00:02:21,399
the manifest file. If you observe one thing very carefully, let me get into the configuration file.

25
00:02:21,400 --> 00:02:25,566
where we have provided this particular template and

26
00:02:25,566 --> 00:02:28,532
This is having proper alignment and wherever

27
00:02:28,533 --> 00:02:33,566
I'm going to include this particular alignment will not be considered when I'm going to include using

28
00:02:33,566 --> 00:02:38,699
the keyword template. There is another option using include that we will be seeing it later.

29
00:02:38,700 --> 00:02:43,000
And this particular include is not going to consider this particular space.

30
00:02:43,000 --> 00:02:49,200
I can go ahead and delete them as well. Let me delete them.

31
00:02:49,200 --> 00:02:57,666
And do the dry run. This is also producing the same result. So within the template

32
00:02:57,666 --> 00:03:04,032
The important thing to remember is the space or indentation within the inner template and not in the place

33
00:03:04,033 --> 00:03:08,599
where we are going to include the template using that template keyword.

34
00:03:08,600 --> 00:03:14,500
The reason why I am concentrating on the indentation, while doing the template programming for the yaml file

35
00:03:14,500 --> 00:03:19,500
the indentation is where most of the mistakes used to happen.

36
00:03:19,500 --> 00:03:25,033
So in a quick summary we have seen how to create a template and include that within another template.

37
00:03:25,033 --> 00:03:29,166
The next section we are going to see how to have this particular template

38
00:03:29,166 --> 00:03:33,032
In a separate file and include within another template file.

